From 465b8c005d0096f1772ca8d2e67f275854096e99 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 25 Jan 2025 12:22:05 +0100 Subject: [PATCH] fix: provide LoadOutPresets & Ships in missionInventoryUpdate response --- src/controllers/api/inventoryController.ts | 20 +++++++++---------- .../api/missionInventoryUpdateController.ts | 9 +++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/controllers/api/inventoryController.ts b/src/controllers/api/inventoryController.ts index 60d02aeb..08b9386e 100644 --- a/src/controllers/api/inventoryController.ts +++ b/src/controllers/api/inventoryController.ts @@ -1,6 +1,6 @@ import { RequestHandler } from "express"; import { getAccountForRequest } from "@/src/services/loginService"; -import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; +import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; import { config } from "@/src/services/configService"; import allDialogue from "@/static/fixed_responses/allDialogue.json"; import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes"; @@ -51,6 +51,13 @@ export const inventoryController: RequestHandler = async (request, response) => await inventory.save(); } + response.json(await getInventoryResponse(inventory, "xpBasedLevelCapDisabled" in request.query)); +}; + +export const getInventoryResponse = async ( + inventory: TInventoryDatabaseDocument, + xpBasedLevelCapDisabled: boolean +): Promise => { const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>( "LoadOutPresets" ); @@ -59,15 +66,6 @@ export const inventoryController: RequestHandler = async (request, response) => ); const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON(); - applyInventoryResponseOverrides(inventoryResponse, "xpBasedLevelCapDisabled" in request.query); - - response.json(inventoryResponse); -}; - -export const applyInventoryResponseOverrides = ( - inventoryResponse: IInventoryClient, - xpBasedLevelCapDisabled: boolean -): void => { if (config.infiniteCredits) { inventoryResponse.RegularCredits = 999999999; } @@ -260,6 +258,8 @@ export const applyInventoryResponseOverrides = ( inventoryResponse.HasOwnedVoidProjectionsPreviously = true; inventoryResponse.LastInventorySync = toOid(new Types.ObjectId()); + + return inventoryResponse; }; const addString = (arr: string[], str: string): void => { diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index ba2ae9bc..63579caf 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -8,8 +8,7 @@ import { calculateFinalCredits } from "@/src/services/missionInventoryUpdateService"; import { getInventory } from "@/src/services/inventoryService"; -import { applyInventoryResponseOverrides } from "./inventoryController"; -import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes"; +import { getInventoryResponse } from "./inventoryController"; /* **** INPUT **** @@ -61,8 +60,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) if (missionReport.MissionStatus !== "GS_SUCCESS") { await inventory.save(); - const inventoryResponse = inventory.toJSON(); - applyInventoryResponseOverrides(inventoryResponse, true); + const inventoryResponse = await getInventoryResponse(inventory, true); res.json({ InventoryJson: JSON.stringify(inventoryResponse), MissionRewards: [] @@ -83,8 +81,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) }); await inventory.save(); - const inventoryResponse = inventory.toJSON(); - applyInventoryResponseOverrides(inventoryResponse, true); + const inventoryResponse = await getInventoryResponse(inventory, true); //TODO: figure out when to send inventory. it is needed for many cases. res.json({