mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(#46): Add boxes page
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user