From 6bed17f2e3625ed2bfa7798d4786d98a8aba911e Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:01:54 +0100 Subject: [PATCH] breaking: remove multi-folder stats, and log warnings if they are used --- server/src/lib/showcase/get-related.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/src/lib/showcase/get-related.ts b/server/src/lib/showcase/get-related.ts index 767cd9023..675abb76f 100644 --- a/server/src/lib/showcase/get-related.ts +++ b/server/src/lib/showcase/get-related.ts @@ -25,11 +25,24 @@ export async function GetRelatedStatDocuments(stat: ShowcaseStatDetails, game: G } case "folder": { - const folders = await db.folders.find({ - folderID: { $in: Array.isArray(stat.folderID) ? stat.folderID : [stat.folderID] }, + if (Array.isArray(stat.folderID)) { + logger.warn( + `This stat is corrupt and attempted to use multiple folderIDs. This is no longer supported. Check that migrations have ran.`, + { stat } + ); + throw new Error(`Legacy FolderIDs used in showcase stat.`); + } + + const folder = await db.folders.findOne({ + folderID: stat.folderID, }); - return { folders }; + if (!folder) { + logger.error(`This stat refers to a folder that does not exist?`, { stat }); + throw new Error(`Stat refers to folder that no longer exists.`); + } + + return { folder }; } default: {