fix: provide LoadOutPresets & Ships in missionInventoryUpdate response (#869)

This commit is contained in:
Sainan 2025-01-25 13:12:49 +01:00 committed by GitHub
parent 6a427018e3
commit cb7c15a382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { getAccountForRequest } from "@/src/services/loginService"; 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 { config } from "@/src/services/configService";
import allDialogue from "@/static/fixed_responses/allDialogue.json"; import allDialogue from "@/static/fixed_responses/allDialogue.json";
import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes"; import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
@ -51,6 +51,13 @@ export const inventoryController: RequestHandler = async (request, response) =>
await inventory.save(); await inventory.save();
} }
response.json(await getInventoryResponse(inventory, "xpBasedLevelCapDisabled" in request.query));
};
export const getInventoryResponse = async (
inventory: TInventoryDatabaseDocument,
xpBasedLevelCapDisabled: boolean
): Promise<IInventoryClient> => {
const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>( const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>(
"LoadOutPresets" "LoadOutPresets"
); );
@ -59,15 +66,6 @@ export const inventoryController: RequestHandler = async (request, response) =>
); );
const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryClient>(); const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryClient>();
applyInventoryResponseOverrides(inventoryResponse, "xpBasedLevelCapDisabled" in request.query);
response.json(inventoryResponse);
};
export const applyInventoryResponseOverrides = (
inventoryResponse: IInventoryClient,
xpBasedLevelCapDisabled: boolean
): void => {
if (config.infiniteCredits) { if (config.infiniteCredits) {
inventoryResponse.RegularCredits = 999999999; inventoryResponse.RegularCredits = 999999999;
} }
@ -260,6 +258,8 @@ export const applyInventoryResponseOverrides = (
inventoryResponse.HasOwnedVoidProjectionsPreviously = true; inventoryResponse.HasOwnedVoidProjectionsPreviously = true;
inventoryResponse.LastInventorySync = toOid(new Types.ObjectId()); inventoryResponse.LastInventorySync = toOid(new Types.ObjectId());
return inventoryResponse;
}; };
const addString = (arr: string[], str: string): void => { const addString = (arr: string[], str: string): void => {

View File

@ -8,8 +8,7 @@ import {
calculateFinalCredits calculateFinalCredits
} from "@/src/services/missionInventoryUpdateService"; } from "@/src/services/missionInventoryUpdateService";
import { getInventory } from "@/src/services/inventoryService"; import { getInventory } from "@/src/services/inventoryService";
import { applyInventoryResponseOverrides } from "./inventoryController"; import { getInventoryResponse } from "./inventoryController";
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
/* /*
**** INPUT **** **** INPUT ****
@ -61,8 +60,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
if (missionReport.MissionStatus !== "GS_SUCCESS") { if (missionReport.MissionStatus !== "GS_SUCCESS") {
await inventory.save(); await inventory.save();
const inventoryResponse = inventory.toJSON<IInventoryClient>(); const inventoryResponse = await getInventoryResponse(inventory, true);
applyInventoryResponseOverrides(inventoryResponse, true);
res.json({ res.json({
InventoryJson: JSON.stringify(inventoryResponse), InventoryJson: JSON.stringify(inventoryResponse),
MissionRewards: [] MissionRewards: []
@ -83,8 +81,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
}); });
await inventory.save(); await inventory.save();
const inventoryResponse = inventory.toJSON<IInventoryClient>(); const inventoryResponse = await getInventoryResponse(inventory, true);
applyInventoryResponseOverrides(inventoryResponse, true);
//TODO: figure out when to send inventory. it is needed for many cases. //TODO: figure out when to send inventory. it is needed for many cases.
res.json({ res.json({