fix: provide LoadOutPresets & Ships in missionInventoryUpdate response
This commit is contained in:
parent
6a427018e3
commit
465b8c005d
@ -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<IInventoryClient> => {
|
||||
const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>(
|
||||
"LoadOutPresets"
|
||||
);
|
||||
@ -59,15 +66,6 @@ export const inventoryController: RequestHandler = async (request, response) =>
|
||||
);
|
||||
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) {
|
||||
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 => {
|
||||
|
@ -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<IInventoryClient>();
|
||||
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<IInventoryClient>();
|
||||
applyInventoryResponseOverrides(inventoryResponse, true);
|
||||
const inventoryResponse = await getInventoryResponse(inventory, true);
|
||||
|
||||
//TODO: figure out when to send inventory. it is needed for many cases.
|
||||
res.json({
|
||||
|
Loading…
x
Reference in New Issue
Block a user