MissionInventoryUpdate(not completed), Mod upgrade, Booster purchase #49

Merged
holmityd merged 40 commits from interface-names into main 2023-09-06 03:02:54 -07:00
4 changed files with 47 additions and 24 deletions
Showing only changes of commit f054db1327 - Show all commits

View File

@ -1,6 +1,7 @@
import { RequestHandler } from "express";
import { Request, Response } from "express";
import { missionInventoryUpdate } from "@/src/services/inventoryService";
import fs from 'fs';
import fs from "fs";
import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
/*
- [ ] crossPlaySetting
- [ ] rewardsMultiplier
@ -39,25 +40,22 @@ import fs from 'fs';
- [ ] FpsMax
- [ ] FpsSamples
*/
const missionInventoryUpdateController: RequestHandler = async (req, res) => {
fs.writeFile("./tmp/missionInventoryUpdate", req.body,(err)=>{
if(err)
return console.log(err);
}); // temp log, !!! tmp folder need on main dir
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
const [data, _secondIGuessIsSalt] = String(req.body).split("\n");
const [data] = String(req.body).split("\n");
const id = req.query.accountId as string;
// TODO - salt check
try {
const parsedData = JSON.parse(data);
if (typeof parsedData !== 'object' || parsedData === null)
throw new Error('Invalid data format');
const parsedData = JSON.parse(data) as MissionInventoryUpdate;
if (typeof parsedData !== "object" || parsedData === null) throw new Error("Invalid data format");
OrdisPrime commented 2023-09-05 05:35:07 -07:00 (Migrated from github.com)
Review

what is the purpose of this?

what is the purpose of this?
OrdisPrime commented 2023-09-05 05:43:03 -07:00 (Migrated from github.com)
Review

can you explain what the difference is between missioncredits and MissionCredits?

can you explain what the difference is between missioncredits and MissionCredits?
OrdisPrime commented 2023-09-05 05:46:03 -07:00 (Migrated from github.com)
Review

can you please use brackets like:
if (something){
expression;
}

can you please use brackets like: if (something){ expression; }
OrdisPrime commented 2023-09-05 05:46:25 -07:00 (Migrated from github.com)
Review

it makes it easier to read

it makes it easier to read
OrdisPrime commented 2023-09-05 05:47:38 -07:00 (Migrated from github.com)
Review

where possible: instead of "i" or "j" use descriptive names such as rawUpgrade or so

where possible: instead of "i" or "j" use descriptive names such as rawUpgrade or so
OrdisPrime commented 2023-09-05 05:49:43 -07:00 (Migrated from github.com)
Review

perhaps make a function for this logic.
A controller should only "control" the calling of functions, with as little logic as possible.
You could make a service/missionInventoryUpdateService and put all the logic there, while you call those functions from the controller. Some logic in the controller is totally fine.

perhaps make a function for this logic. A controller should only "control" the calling of functions, with as little logic as possible. You could make a service/missionInventoryUpdateService and put all the logic there, while you call those functions from the controller. Some logic in the controller is totally fine.
OrdisPrime commented 2023-09-05 05:50:28 -07:00 (Migrated from github.com)
Review

move types and interfaces into types/missionInventoryTypes

move types and interfaces into types/missionInventoryTypes
await missionInventoryUpdate(parsedData, id);
} catch (err) {
console.error('Error parsing JSON data:', err);
console.error("Error parsing JSON data:", err);
}
// TODO - get original response

View File

@ -0,0 +1,7 @@
import { RequestHandler } from "express";
const viewController: RequestHandler = (_req, res) => {
res.json({});
};
export { viewController };

View File

@ -1,7 +1,14 @@
import { viewController } from "../controllers/api/viewController";
import { uploadController } from "@/src/controllers/stats/uploadController";
import express from "express";
const statsRouter = express.Router();
// get
statsRouter.get("/view.php", viewController);
// post
statsRouter.post("/upload.php", uploadController);
export { statsRouter };

View File

@ -6,7 +6,12 @@ import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
import { SlotType } from "@/src/types/purchaseTypes";
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { MissionInventoryUpdate, MissionInventoryUpdateCard, MissionInventoryUpdateGear, MissionInventoryUpdateItem } from "../types/missionInventoryUpdateType";
import {
MissionInventoryUpdate,
MissionInventoryUpdateCard,
MissionInventoryUpdateGear,
MissionInventoryUpdateItem
} from "../types/missionInventoryUpdateType";
const createInventory = async (accountOwnerId: Types.ObjectId) => {
try {
@ -113,21 +118,27 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
// TODO - multipliers logic
const addGearExpByCategory = (gearArray: MissionInventoryUpdateGear[] | undefined, categoryName: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
const addGearExpByCategory = (
gearArray: MissionInventoryUpdateGear[] | undefined,
categoryName: "Pistols" | "LongGuns" | "Melee" | "Suits"
) => {
const category = inventory[categoryName];
gearArray?.forEach(({ ItemId, XP }) => {
const itemIndex = category.findIndex(i => i._id?.equals(ItemId.$oid));
const item = category[itemIndex];
if (itemIndex !== -1 && item.XP!=undefined) {
if (itemIndex !== -1 && item.XP != undefined) {
item.XP += XP;
inventory.markModified(`${categoryName}.${itemIndex}.XP`);
}
});
};
const addItemsByCategory = (itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined, categoryName: 'RawUpgrades'|'MiscItems') => {
const addItemsByCategory = (
itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined,
categoryName: "RawUpgrades" | "MiscItems"
) => {
const category = inventory[categoryName];
itemsArray?.forEach(({ ItemCount, ItemType }) => {
@ -142,13 +153,13 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
});
};
inventory.RegularCredits += RegularCredits||0;
addGearExpByCategory(Pistols, 'Pistols');
addGearExpByCategory(LongGuns, 'LongGuns');
addGearExpByCategory(Melee, 'Melee');
addGearExpByCategory(Suits, 'Suits');
addItemsByCategory(RawUpgrades, 'RawUpgrades'); // TODO - check mods fusion level
addItemsByCategory(MiscItems, 'MiscItems');
inventory.RegularCredits += RegularCredits || 0;
addGearExpByCategory(Pistols, "Pistols");
addGearExpByCategory(LongGuns, "LongGuns");
addGearExpByCategory(Melee, "Melee");
addGearExpByCategory(Suits, "Suits");
addItemsByCategory(RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
addItemsByCategory(MiscItems, "MiscItems");
// TODO - save ChallengeProgress (idk where to save)