adjust mission update controller
This commit is contained in:
parent
5649c5bf86
commit
989f8eda4b
@ -55,29 +55,25 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
|
||||
|
||||
const missionReport = getJSONfromString<IMissionInventoryUpdateRequest>((req.body as string).toString());
|
||||
|
||||
if (missionReport.MissionStatus !== "GS_SUCCESS") {
|
||||
logger.debug(`Mission failed: ${missionReport.RewardInfo?.node}`);
|
||||
//todo: return expected response for failed mission
|
||||
res.json([]);
|
||||
return;
|
||||
//duvirisadjob does not provide missionStatus
|
||||
}
|
||||
|
||||
const inventory = await getInventory(accountId);
|
||||
|
||||
const missionRewardsResults = await addMissionRewards(inventory, missionReport);
|
||||
|
||||
if (!missionRewardsResults) {
|
||||
logger.error("Failed to add mission rewards");
|
||||
res.status(500).json({ error: "Failed to add mission rewards" });
|
||||
if (missionReport.MissionStatus !== "GS_SUCCESS") {
|
||||
const InventoryJson = JSON.stringify((await inventory.save()).toJSON());
|
||||
|
||||
res.json({ InventoryJson, MissionRewards: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!missionRewardsResults) {
|
||||
throw new Error("Failed to add mission rewards, should not happen");
|
||||
}
|
||||
|
||||
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
|
||||
|
||||
const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport);
|
||||
|
||||
//todo ? can go after not awaiting
|
||||
//creditBonus is not correct for mirage mission 3
|
||||
const credits = calculateFinalCredits(inventory, {
|
||||
missionCompletionCredits,
|
||||
|
@ -21,6 +21,7 @@ import { HydratedDocument } from "mongoose";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
import { getLevelKeyRewards, getNode } from "@/src/services/itemDataService";
|
||||
import { InventoryDocumentProps, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { getEntriesUnsafe } from "@/src/utils/ts-utils";
|
||||
|
||||
const getRotations = (rotationCount: number): number[] => {
|
||||
if (rotationCount === 0) return [0];
|
||||
@ -64,12 +65,6 @@ export const fusionBundles: Record<string, number> = {
|
||||
"/Lotus/Upgrades/Mods/FusionBundles/RareFusionBundle": 80
|
||||
};
|
||||
|
||||
type Entries<T, K extends keyof T = keyof T> = (K extends unknown ? [K, T[K]] : never)[];
|
||||
|
||||
function getEntriesUnsafe<T extends object>(object: T): Entries<T> {
|
||||
return Object.entries(object) as Entries<T>;
|
||||
}
|
||||
|
||||
//type TMissionInventoryUpdateKeys = keyof IMissionInventoryUpdateRequest;
|
||||
//const ignoredInventoryUpdateKeys = ["FpsAvg", "FpsMax", "FpsMin", "FpsSamples"] satisfies TMissionInventoryUpdateKeys[]; // for keys with no meaning for this server
|
||||
//type TignoredInventoryUpdateKeys = (typeof ignoredInventoryUpdateKeys)[number];
|
||||
@ -185,7 +180,7 @@ export const addMissionRewards = async (
|
||||
{ RewardInfo: rewardInfo, LevelKeyName: levelKeyName, Missions: missions }: IMissionInventoryUpdateRequest
|
||||
) => {
|
||||
if (!rewardInfo) {
|
||||
logger.error("no reward info provided");
|
||||
logger.warn("no reward info provided");
|
||||
return;
|
||||
}
|
||||
|
||||
|
5
src/utils/ts-utils.ts
Normal file
5
src/utils/ts-utils.ts
Normal file
@ -0,0 +1,5 @@
|
||||
type Entries<T, K extends keyof T = keyof T> = (K extends unknown ? [K, T[K]] : never)[];
|
||||
|
||||
export function getEntriesUnsafe<T extends object>(object: T): Entries<T> {
|
||||
return Object.entries(object) as Entries<T>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user