mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-12 18:43:45 +00:00
feat(*): Enable filtering to either do a forms dex or a regular dex
This commit is contained in:
@@ -3,9 +3,13 @@ import CatchRecordModel, { type CatchRecord } from '$lib/models/CatchRecord';
|
||||
import { CombinedData } from '$lib/models/CombinedData';
|
||||
|
||||
class CombinedDataRepository {
|
||||
async findCombinedData(page: number = 1, limit: number = 20): Promise<CombinedData[]> {
|
||||
async findCombinedData(
|
||||
page: number = 1,
|
||||
limit: number = 20,
|
||||
enableForms: boolean = true
|
||||
): Promise<CombinedData[]> {
|
||||
const skip = (page - 1) * limit;
|
||||
const combinedData: CombinedData[] = await PokedexEntryModel.aggregate([
|
||||
const pipeline: any[] = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'catchrecords',
|
||||
@@ -29,7 +33,17 @@ class CombinedDataRepository {
|
||||
},
|
||||
{ $skip: skip },
|
||||
{ $limit: limit }
|
||||
]).exec();
|
||||
];
|
||||
|
||||
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);
|
||||
@@ -40,8 +54,14 @@ class CombinedDataRepository {
|
||||
}));
|
||||
}
|
||||
|
||||
async countCombinedData(): Promise<number> {
|
||||
return PokedexEntryModel.countDocuments().exec();
|
||||
async countCombinedData(enableForms: boolean): Promise<number> {
|
||||
const filter: any = {};
|
||||
|
||||
if (!enableForms) {
|
||||
filter['boxPlacement.box'] = { $ne: null };
|
||||
}
|
||||
|
||||
return PokedexEntryModel.countDocuments(filter).exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user