MissionInventoryUpdate - challenges
This commit is contained in:
parent
a1c2815728
commit
4c8536a339
@ -1,6 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import { RequestHandler } from "express";
|
||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
|
||||
import fs from "fs";
|
||||
import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
|
||||
/*
|
||||
- [ ] crossPlaySetting
|
||||
@ -40,11 +39,9 @@ import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
|
||||
- [ ] FpsMax
|
||||
- [ ] 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 id = req.query.accountId as string;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { Types } from "mongoose";
|
||||
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
|
||||
import { SlotType } from "@/src/types/purchaseTypes";
|
||||
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 {
|
||||
MissionInventoryUpdate,
|
||||
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> => {
|
||||
const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
|
||||
const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits, ChallengeProgress } = data;
|
||||
const inventory = await getInventory(accountId);
|
||||
|
||||
// TODO - multipliers logic
|
||||
@ -162,8 +177,7 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
|
||||
addGearExpByCategory(inventory, Suits, "Suits");
|
||||
addItemsByCategory(inventory, RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
|
||||
addItemsByCategory(inventory, MiscItems, "MiscItems");
|
||||
|
||||
// TODO - save ChallengeProgress (idk where to save)
|
||||
addChallenges(inventory, ChallengeProgress);
|
||||
|
||||
await inventory.save();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user