feat(#46): Componentise the boxes view

This commit is contained in:
Josh Creek
2024-07-17 21:11:58 +01:00
parent e4ca722de7
commit 4d9d5e74d7
5 changed files with 332 additions and 120 deletions
+21 -1
View File
@@ -3,7 +3,11 @@ import CatchRecordModel, { type CatchRecord } from '$lib/models/CatchRecord';
import { CombinedData } from '$lib/models/CombinedData';
class CombinedDataRepository {
async findAllCombinedData(enableForms: boolean = true): Promise<CombinedData[]> {
async findAllCombinedData(
enableForms: boolean = true,
region: string = '',
game: string = ''
): Promise<CombinedData[]> {
const pipeline: any[] = [
{
$lookup: {
@@ -36,6 +40,22 @@ class CombinedDataRepository {
});
}
if (region.length > 0) {
pipeline.unshift({
$match: {
regionToCatchIn: region
}
});
}
if (game.length > 0) {
pipeline.unshift({
$match: {
gamesToCatchIn: { $in: [game] }
}
});
}
const combinedData: CombinedData[] = await PokedexEntryModel.aggregate(pipeline).exec();
// Filter out entries with no catch records