feat(*): Add ability to filter by game and region

This commit is contained in:
Josh Creek
2024-07-14 20:51:05 +01:00
parent 62c03f41eb
commit 0285725b6d
3 changed files with 126 additions and 16 deletions
+4 -2
View File
@@ -6,16 +6,18 @@ export const GET = async ({ url }) => {
const page = parseInt(url.searchParams.get('page') || '1', 10);
const limit = parseInt(url.searchParams.get('limit') || '20', 10);
const enableForms = url.searchParams.get('enableForms') === 'true';
const region = url.searchParams.get('region');
const game = url.searchParams.get('game');
try {
await dbConnect();
const repo = new CombinedDataRepository();
const combinedData = await repo.findCombinedData(page, limit, enableForms);
const combinedData = await repo.findCombinedData(page, limit, enableForms, region, game);
if (combinedData.length === 0) {
return json({ error: 'No combined data found' }, { status: 404 });
}
const totalCount = await repo.countCombinedData(enableForms);
const totalCount = await repo.countCombinedData(enableForms, region, game);
const totalPages = Math.ceil(totalCount / limit);
return json({ combinedData, totalPages });