Skip to content

Commit d5ae688

Browse files
committed
Fix getting the collections and projects count from TinyBird
Signed-off-by: Raúl Santos <4837+borfast@users.noreply.github.com>
1 parent 98c9440 commit d5ae688

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

frontend/server/api/collection/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ export default defineEventHandler(async (event): Promise<Pagination<Collection>
4141
orderByDirection,
4242
});
4343

44+
type CollectionCount = {'count(id)': number};
45+
const collectionCountResult = await fetchFromTinybird<CollectionCount[]>('/v0/pipes/collections_list.json', {
46+
count: true,
47+
});
48+
4449
const data: Pagination<Collection> = {
4550
page,
4651
pageSize,
47-
total: res.rows,
52+
total: collectionCountResult.data[0]?.['count(id)'] || 0,
4853
data: res.data,
4954
}
5055

5156
return data
5257
} catch (error) {
53-
console.error('Error collection list:', error);
58+
console.error('Error fetching collection list from TinyBird:', error);
5459
throw createError({statusCode: 500, statusMessage: 'Internal Server Error'});
5560
}
5661
});

frontend/server/api/project/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ export default defineEventHandler(async (event): Promise<Pagination<Project> | E
5656
orderByDirection,
5757
});
5858

59+
type ProjectCount = {'count(id)': number};
60+
const projectCountResult = await fetchFromTinybird<ProjectCount[]>('/v0/pipes/projects_list.json', {
61+
count: true,
62+
});
63+
5964
const data: Pagination<Project> = {
6065
page,
6166
pageSize,
62-
total: res.rows,
67+
total: projectCountResult.data[0]?.['count(id)'] || 0,
6368
data: res.data,
6469
}
6570

6671
return data;
6772
} catch (error) {
68-
console.error('Error fetching project list:', error);
73+
console.error('Error fetching project list from TinyBird:', error);
6974
throw createError({statusCode: 500, statusMessage: 'Internal Server Error'});
7075
}
7176
});

0 commit comments

Comments
 (0)