MissionInventoryUpdate(not completed), Mod upgrade, Booster purchase #49
@ -1,6 +1,5 @@
 | 
				
			|||||||
import { Request, Response } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
					import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
				
			||||||
import fs from "fs";
 | 
					 | 
				
			||||||
import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
 | 
					import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
- [ ]  crossPlaySetting
 | 
					- [ ]  crossPlaySetting
 | 
				
			||||||
@ -40,11 +39,9 @@ import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
 | 
				
			|||||||
- [ ]  FpsMax
 | 
					- [ ]  FpsMax
 | 
				
			||||||
- [ ]  FpsSamples
 | 
					- [ ]  FpsSamples
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
const missionInventoryUpdateController = async (req: Request, res: Response) => {
 | 
					 | 
				
			||||||
    fs.writeFile("./tmp/missionInventoryUpdate", req.body as string, err => {
 | 
					 | 
				
			||||||
        if (err) return console.log(err);
 | 
					 | 
				
			||||||
    }); // temp log, !!! tmp folder need on main dir
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
				
			||||||
 | 
					const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const [data] = String(req.body).split("\n");
 | 
					    const [data] = String(req.body).split("\n");
 | 
				
			||||||
    const id = req.query.accountId as string;
 | 
					    const id = req.query.accountId as string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ import { Types } from "mongoose";
 | 
				
			|||||||
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
 | 
					import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
 | 
				
			||||||
import { SlotType } from "@/src/types/purchaseTypes";
 | 
					import { SlotType } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
					import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
				
			||||||
import { FlavourItem, IInventoryDatabaseDocument } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { ChallengeProgress, FlavourItem, IInventoryDatabaseDocument } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    MissionInventoryUpdate,
 | 
					    MissionInventoryUpdate,
 | 
				
			||||||
    MissionInventoryUpdateCard,
 | 
					    MissionInventoryUpdateCard,
 | 
				
			||||||
@ -149,8 +149,23 @@ const addItemsByCategory = (
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: ChallengeProgress[] | undefined) => {
 | 
				
			||||||
 | 
					    const category = inventory.ChallengeProgress;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    itemsArray?.forEach(({ Name, Progress }) => {
 | 
				
			||||||
 | 
					        const itemIndex = category.findIndex(i => i.Name === Name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (itemIndex !== -1) {
 | 
				
			||||||
 | 
					            category[itemIndex].Progress += Progress;
 | 
				
			||||||
 | 
					            inventory.markModified(`ChallengeProgress.${itemIndex}.ItemCount`);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            category.push({ Name, Progress });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accountId: string): Promise<void> => {
 | 
					export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accountId: string): Promise<void> => {
 | 
				
			||||||
    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
					    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits, ChallengeProgress } = data;
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO - multipliers logic
 | 
					    // TODO - multipliers logic
 | 
				
			||||||
@ -162,8 +177,7 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
 | 
				
			|||||||
    addGearExpByCategory(inventory, Suits, "Suits");
 | 
					    addGearExpByCategory(inventory, Suits, "Suits");
 | 
				
			||||||
    addItemsByCategory(inventory, RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
 | 
					    addItemsByCategory(inventory, RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
 | 
				
			||||||
    addItemsByCategory(inventory, MiscItems, "MiscItems");
 | 
					    addItemsByCategory(inventory, MiscItems, "MiscItems");
 | 
				
			||||||
 | 
					    addChallenges(inventory, ChallengeProgress);
 | 
				
			||||||
    // TODO - save ChallengeProgress (idk where to save)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user