fix: adjust mission update controller to add xp when aborting mission. #864
@ -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,
 | 
				
			||||||
 | 
				
			|||||||
@ -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
									
								
							
							
						
						
									
										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