forked from OpenWF/SpaceNinjaServer
fix: provide LoadOutPresets & Ships in missionInventoryUpdate response (#869)
This commit is contained in:
parent
6a427018e3
commit
cb7c15a382
@ -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 => {
|
||||||
|
@ -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({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user