fix: adjust mission update controller to add xp when aborting mission(#864)

This commit is contained in:
OrdisPrime 2025-01-24 16:17:59 +01:00 committed by GitHub
parent 080b466bfc
commit 57061073be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 29 deletions

View File

@ -8,7 +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 { logger } from "@/src/utils/logger";
/* /*
**** INPUT **** **** INPUT ****
- [ ] crossPlaySetting - [ ] crossPlaySetting
@ -52,32 +52,23 @@ import { logger } from "@/src/utils/logger";
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => { export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const missionReport = getJSONfromString<IMissionInventoryUpdateRequest>((req.body as string).toString()); 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 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" });
return;
}
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport); const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport);
//todo ? can go after not awaiting if (missionReport.MissionStatus !== "GS_SUCCESS") {
const InventoryJson = JSON.stringify((await inventory.save()).toJSON());
res.json({ InventoryJson, MissionRewards: [] });
return;
}
const missionRewardsResults = await addMissionRewards(inventory, missionReport);
if (!missionRewardsResults) {
throw new Error("Failed to add mission rewards, should not happen");
}
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
//creditBonus is not correct for mirage mission 3 //creditBonus is not correct for mirage mission 3
const credits = calculateFinalCredits(inventory, { const credits = calculateFinalCredits(inventory, {
missionCompletionCredits, missionCompletionCredits,

View File

@ -21,6 +21,7 @@ import { HydratedDocument } from "mongoose";
import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { IInventoryChanges } from "@/src/types/purchaseTypes";
import { getLevelKeyRewards, getNode } from "@/src/services/itemDataService"; import { getLevelKeyRewards, getNode } from "@/src/services/itemDataService";
import { InventoryDocumentProps, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; import { InventoryDocumentProps, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
import { getEntriesUnsafe } from "@/src/utils/ts-utils";
const getRotations = (rotationCount: number): number[] => { const getRotations = (rotationCount: number): number[] => {
if (rotationCount === 0) return [0]; if (rotationCount === 0) return [0];
@ -64,12 +65,6 @@ export const fusionBundles: Record<string, number> = {
"/Lotus/Upgrades/Mods/FusionBundles/RareFusionBundle": 80 "/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; //type TMissionInventoryUpdateKeys = keyof IMissionInventoryUpdateRequest;
//const ignoredInventoryUpdateKeys = ["FpsAvg", "FpsMax", "FpsMin", "FpsSamples"] satisfies TMissionInventoryUpdateKeys[]; // for keys with no meaning for this server //const ignoredInventoryUpdateKeys = ["FpsAvg", "FpsMax", "FpsMin", "FpsSamples"] satisfies TMissionInventoryUpdateKeys[]; // for keys with no meaning for this server
//type TignoredInventoryUpdateKeys = (typeof ignoredInventoryUpdateKeys)[number]; //type TignoredInventoryUpdateKeys = (typeof ignoredInventoryUpdateKeys)[number];
@ -185,7 +180,7 @@ export const addMissionRewards = async (
{ RewardInfo: rewardInfo, LevelKeyName: levelKeyName, Missions: missions }: IMissionInventoryUpdateRequest { RewardInfo: rewardInfo, LevelKeyName: levelKeyName, Missions: missions }: IMissionInventoryUpdateRequest
) => { ) => {
if (!rewardInfo) { if (!rewardInfo) {
logger.error("no reward info provided"); logger.warn("no reward info provided");
return; return;
} }

5
src/utils/ts-utils.ts Normal file
View 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>;
}