From fe451171abce8cdc6600c57b17321d3995faed26 Mon Sep 17 00:00:00 2001 From: nk Date: Sun, 3 Sep 2023 14:31:44 -0500 Subject: [PATCH] Fix it... again --- .../api/missionInventoryUpdateController.ts | 3 +-- src/services/inventoryService.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 5eba667d..c444bf9a 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -44,7 +44,6 @@ import { IMissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType" const missionInventoryUpdateController: RequestHandler = async (req, res) => { const id = req.query.accountId as string; - // Remove the hash, which is added directly below the JSON data. const [data] = String(req.body).split("\n"); try { @@ -55,7 +54,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => { console.error("Error parsing JSON data:", err); } - // TODO - get original response + // TODO - Return the updated inventory the way the game does it. res.json({}); }; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 2b79db76..d12a0104 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -81,10 +81,24 @@ export const updateCurrency = async (price: number, usePremium: boolean, account return { [currencyName]: -price }; }; +// TODO: AffiliationMods support (Nightwave). export const updateGeneric = async (data: IGenericUpdate, accountId: string) => { const inventory = await getInventory(accountId); - data.NodeIntrosCompleted = data.NodeIntrosCompleted.concat(inventory.NodeIntrosCompleted); + + // Make it an array for easier parsing. + if (typeof data.NodeIntrosCompleted === "string") { + data.NodeIntrosCompleted = [ data.NodeIntrosCompleted ]; + } + + // Combine the two arrays into one. + data.NodeIntrosCompleted = inventory.NodeIntrosCompleted.concat(data.NodeIntrosCompleted); + + // Remove duplicate entries. + const nodes = [ ...new Set(data.NodeIntrosCompleted) ]; + + inventory.NodeIntrosCompleted = nodes; await inventory.save(); + return data; }; @@ -184,7 +198,7 @@ export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, acco const inventory = await getInventory(accountId); // Currency - // !!! TODO: Make a helper specifically for adding currencies with negative/positive checks shared between them. + // TODO: Make a helper specifically for adding currencies with negative/positive checks shared between them. // TODO - Multipliers (from Boosters or otherwise). const credits = RegularCredits as number; inventory.RegularCredits += credits < 0 ? Math.abs(credits) : credits; // If credits are negative, flip them.