feat(#46): Add boxes page

This commit is contained in:
Josh Creek
2024-07-15 20:49:36 +01:00
parent d3b7e7f5a9
commit 2ad7e219a2
5 changed files with 182 additions and 1 deletions
@@ -3,6 +3,50 @@ import CatchRecordModel, { type CatchRecord } from '$lib/models/CatchRecord';
import { CombinedData } from '$lib/models/CombinedData';
class CombinedDataRepository {
async findAllCombinedData(enableForms: boolean = true): Promise<CombinedData[]> {
const pipeline: any[] = [
{
$lookup: {
from: 'catchrecords',
localField: '_id',
foreignField: 'pokedexEntryId',
as: 'catchRecord'
}
},
{
$unwind: {
path: '$catchRecord',
preserveNullAndEmptyArrays: true
}
},
{
$sort: {
'boxPlacementForms.box': 1,
'boxPlacementForms.row': 1,
'boxPlacementForms.column': 1
}
}
];
if (!enableForms) {
pipeline.unshift({
$match: {
'boxPlacement.box': { $ne: null }
}
});
}
const combinedData: CombinedData[] = await PokedexEntryModel.aggregate(pipeline).exec();
// Filter out entries with no catch records
const filteredData = combinedData.filter((data) => data.catchRecord);
return filteredData.map((data) => ({
pokedexEntry: data as PokedexEntry,
catchRecord: data.catchRecord as CatchRecord
}));
}
async findCombinedData(
page: number = 1,
limit: number = 20,