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
2 changed files with 42 additions and 36 deletions
Showing only changes of commit 15ab3f76b1 - Show all commits

View File

@ -1,14 +1,14 @@
import { RequestHandler } from "express";
import { addRawUpgrades, addMiscItems } from "@/src/services/inventoryService";
import { missionInventoryUpdate } from "@/src/services/inventoryService";
import fs from 'fs';
/*
- [ ] crossPlaySetting
- [ ] rewardsMultiplier
- [ ] ActiveBoosters
- [ ] LongGuns
- [ ] Pistols
- [ ] Suits
- [ ] Melee
- [x] LongGuns
- [x] Pistols
- [x] Suits
- [x] Melee
- [x] RawUpgrades
- [x] MiscItems
- [ ] RegularCredits
@ -47,10 +47,9 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
});
const [data, _secondIGuessIsSalt] = String(req.body).split("\n");
const {RawUpgrades, MiscItems} = JSON.parse(data);
const id = req.query.accountId as string;
addRawUpgrades(RawUpgrades, id);
addMiscItems(MiscItems, id);
await missionInventoryUpdate(JSON.parse(data), id);
res.json({});
};
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

View File

@ -2,10 +2,11 @@ import { Inventory } from "@/src/models/inventoryModel";
import new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
import config from "@/config.json";
import { Types } from "mongoose";
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
import { ISuitDatabase, ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
import { SlotType } from "@/src/types/purchaseTypes";
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem, RawUpgrade, MiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem, RawUpgrade, MiscItem, IInventoryDatabase } from "@/src/types/inventoryTypes/inventoryTypes";
import { items } from "@/static/data/items";
const createInventory = async (accountOwnerId: Types.ObjectId) => {
try {
@ -106,35 +107,41 @@ export const addCustomization = async (customizatonName: string, accountId: stri
return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem
};
export const addRawUpgrades = async (rawUpgrades: RawUpgrade[], accountId: string): Promise<void> => {
export const missionInventoryUpdate = async (data: any, accountId: string): Promise<void> => {
const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee } = data;
const inventory = await getInventory(accountId);
rawUpgrades?.forEach(item => {
const { ItemCount, ItemType } = item;
const existingItemIndex = inventory.RawUpgrades.findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) {
inventory.RawUpgrades[existingItemIndex].ItemCount += ItemCount;
inventory.markModified('RawUpgrades.' + existingItemIndex + '.ItemCount');
} else {
inventory.RawUpgrades.push({ ItemCount, ItemType });
const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
gearArray.forEach(({ ItemId, XP }: any) => {
const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid));
if (itemIndex !== -1) {
inventory[category][itemIndex].XP += XP;
inventory.markModified(`${category}.${itemIndex}.XP`);
}
});
await inventory.save();
};
export const addMiscItems = async (miscItems: MiscItem[], accountId: string): Promise<void> => {
const inventory = await getInventory(accountId);
miscItems?.forEach(item => {
const addItemsByCategory = (itemsArray: (RawUpgrade | MiscItem)[], category: 'RawUpgrades'|'MiscItems') => {
itemsArray?.forEach(item => {
const { ItemCount, ItemType } = item;
const existingItemIndex = inventory.MiscItems.findIndex(i => i.ItemType === ItemType);
const existingItemIndex = inventory[category].findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) {
inventory.MiscItems[existingItemIndex].ItemCount += ItemCount;
inventory.markModified('MiscItems.' + existingItemIndex + '.ItemCount');
inventory[category][existingItemIndex].ItemCount += ItemCount;
inventory.markModified(category + '.' + existingItemIndex + '.ItemCount');
} else {
inventory.MiscItems.push({ ItemCount, ItemType });
inventory[category].push({ ItemCount, ItemType });
}
});
};
addGearExpByCategory(Pistols, 'Pistols');
addGearExpByCategory(LongGuns, 'LongGuns');
addGearExpByCategory(Melee, 'Melee');
addGearExpByCategory(Suits, 'Suits');
addItemsByCategory(RawUpgrades, 'RawUpgrades'); // TODO - check mods fusion level
addItemsByCategory(MiscItems, 'MiscItems');
await inventory.save();
};