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 { RequestHandler } from "express";
import { addRawUpgrades, addMiscItems } from "@/src/services/inventoryService"; import { missionInventoryUpdate } from "@/src/services/inventoryService";
import fs from 'fs'; import fs from 'fs';
/* /*
- [ ] crossPlaySetting - [ ] crossPlaySetting
- [ ] rewardsMultiplier - [ ] rewardsMultiplier
- [ ] ActiveBoosters - [ ] ActiveBoosters
- [ ] LongGuns - [x] LongGuns
- [ ] Pistols - [x] Pistols
- [ ] Suits - [x] Suits
- [ ] Melee - [x] Melee
- [x] RawUpgrades - [x] RawUpgrades
- [x] MiscItems - [x] MiscItems
- [ ] RegularCredits - [ ] RegularCredits
@ -47,10 +47,9 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
}); });
const [data, _secondIGuessIsSalt] = String(req.body).split("\n"); const [data, _secondIGuessIsSalt] = String(req.body).split("\n");
const {RawUpgrades, MiscItems} = JSON.parse(data);
const id = req.query.accountId as string; const id = req.query.accountId as string;
addRawUpgrades(RawUpgrades, id);
addMiscItems(MiscItems, id); await missionInventoryUpdate(JSON.parse(data), id);
res.json({}); 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 new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
import config from "@/config.json"; import config from "@/config.json";
import { Types } from "mongoose"; 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 { SlotType } from "@/src/types/purchaseTypes";
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes"; import { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem, RawUpgrade, MiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { FlavourItem, RawUpgrade, MiscItem, IInventoryDatabase } from "@/src/types/inventoryTypes/inventoryTypes";
import { items } from "@/static/data/items";
const createInventory = async (accountOwnerId: Types.ObjectId) => { const createInventory = async (accountOwnerId: Types.ObjectId) => {
try { try {
@ -106,35 +107,41 @@ export const addCustomization = async (customizatonName: string, accountId: stri
return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem 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); const inventory = await getInventory(accountId);
rawUpgrades?.forEach(item => {
const { ItemCount, ItemType } = item;
const existingItemIndex = inventory.RawUpgrades.findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) { const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
inventory.RawUpgrades[existingItemIndex].ItemCount += ItemCount; gearArray.forEach(({ ItemId, XP }: any) => {
inventory.markModified('RawUpgrades.' + existingItemIndex + '.ItemCount'); const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid));
} else { if (itemIndex !== -1) {
inventory.RawUpgrades.push({ ItemCount, ItemType }); inventory[category][itemIndex].XP += XP;
inventory.markModified(`${category}.${itemIndex}.XP`);
} }
}); });
await inventory.save(); };
};
export const addMiscItems = async (miscItems: MiscItem[], accountId: string): Promise<void> => { const addItemsByCategory = (itemsArray: (RawUpgrade | MiscItem)[], category: 'RawUpgrades'|'MiscItems') => {
const inventory = await getInventory(accountId); itemsArray?.forEach(item => {
miscItems?.forEach(item => {
const { ItemCount, ItemType } = 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) { if (existingItemIndex !== -1) {
inventory.MiscItems[existingItemIndex].ItemCount += ItemCount; inventory[category][existingItemIndex].ItemCount += ItemCount;
inventory.markModified('MiscItems.' + existingItemIndex + '.ItemCount'); inventory.markModified(category + '.' + existingItemIndex + '.ItemCount');
} else { } 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(); await inventory.save();
}; };