From e686a2d028cfada2e11ff80afb73c9055bcbc7ba Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 19 Jun 2025 16:18:49 -0700 Subject: [PATCH] chore: report unknown fields in updateChallengeProgress payload (#2210) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2210 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- .../api/updateChallengeProgressController.ts | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/controllers/api/updateChallengeProgressController.ts b/src/controllers/api/updateChallengeProgressController.ts index 51eb88c3..5a7e6467 100644 --- a/src/controllers/api/updateChallengeProgressController.ts +++ b/src/controllers/api/updateChallengeProgressController.ts @@ -4,6 +4,8 @@ import { getAccountForRequest } from "@/src/services/loginService"; import { addChallenges, getInventory } from "@/src/services/inventoryService"; import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes"; import { IAffiliationMods } from "@/src/types/purchaseTypes"; +import { getEntriesUnsafe } from "@/src/utils/ts-utils"; +import { logger } from "@/src/utils/logger"; export const updateChallengeProgressController: RequestHandler = async (req, res) => { const challenges = getJSONfromString(String(req.body)); @@ -13,9 +15,6 @@ export const updateChallengeProgressController: RequestHandler = async (req, res account._id.toString(), "ChallengesFixVersion ChallengeProgress SeasonChallengeHistory Affiliations" ); - if (challenges.ChallengesFixVersion !== undefined) { - inventory.ChallengesFixVersion = challenges.ChallengesFixVersion; - } let affiliationMods: IAffiliationMods[] = []; if (challenges.ChallengeProgress) { affiliationMods = addChallenges( @@ -25,15 +24,30 @@ export const updateChallengeProgressController: RequestHandler = async (req, res challenges.SeasonChallengeCompletions ); } - if (challenges.SeasonChallengeHistory) { - challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => { - const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge); - if (itemIndex !== -1) { - inventory.SeasonChallengeHistory[itemIndex].id = id; - } else { - inventory.SeasonChallengeHistory.push({ challenge, id }); - } - }); + for (const [key, value] of getEntriesUnsafe(challenges)) { + switch (key) { + case "ChallengesFixVersion": + inventory.ChallengesFixVersion = value; + break; + + case "SeasonChallengeHistory": + value!.forEach(({ challenge, id }) => { + const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge); + if (itemIndex !== -1) { + inventory.SeasonChallengeHistory[itemIndex].id = id; + } else { + inventory.SeasonChallengeHistory.push({ challenge, id }); + } + }); + break; + + case "ChallengeProgress": + case "SeasonChallengeCompletions": + case "ChallengePTS": + break; + default: + logger.warn(`unknown challenge progress entry`, { key, value }); + } } await inventory.save(); @@ -43,6 +57,7 @@ export const updateChallengeProgressController: RequestHandler = async (req, res }; interface IUpdateChallengeProgressRequest { + ChallengePTS?: number; ChallengesFixVersion?: number; ChallengeProgress?: IChallengeProgress[]; SeasonChallengeHistory?: ISeasonChallenge[];