From bc25ab0e38c2ee7dd84d2cfd21d512f46b20c5c9 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:03:57 +0100 Subject: [PATCH] fix(*): Fix bug returning 0 for document counts when filtering by region and game --- src/lib/repositories/CombinedDataRepository.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/repositories/CombinedDataRepository.ts b/src/lib/repositories/CombinedDataRepository.ts index 2eee0a1..9d8a69b 100644 --- a/src/lib/repositories/CombinedDataRepository.ts +++ b/src/lib/repositories/CombinedDataRepository.ts @@ -84,17 +84,16 @@ class CombinedDataRepository { } if (game.length > 0) { - // Check if gamesToCatchIn is not already defined in filter - if (!filter['gamesToCatchIn']) { - filter['gamesToCatchIn'] = []; - } - // Add the game to the filter if it's not already included - if (!filter['gamesToCatchIn'].includes(game)) { - filter['gamesToCatchIn'].push(game); - } + filter['gamesToCatchIn'] = { $in: [game] }; } - return PokedexEntryModel.countDocuments(filter).exec(); + try { + const count = await PokedexEntryModel.countDocuments(filter).exec(); + return count; + } catch (error) { + console.error('Error counting documents:', error); + throw error; + } } }