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
5 changed files with 99 additions and 3 deletions
Showing only changes of commit b66fdc17ba - Show all commits

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/.env /.env
/static/data/*.bin /static/data/*.bin
yarn.lock yarn.lock
/tmp

View File

@ -1,6 +1,57 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { addRawUpgrades, addMiscItems } from "@/src/services/inventoryService";
import fs from 'fs';
/*
- [ ] crossPlaySetting
- [ ] rewardsMultiplier
- [ ] ActiveBoosters
- [ ] LongGuns
- [ ] Pistols
- [ ] Suits
- [ ] Melee
- [x] RawUpgrades
- [x] MiscItems
- [ ] RegularCredits
- [ ] RandomUpgradesIdentified
- [ ] MissionFailed
- [ ] MissionStatus
- [ ] CurrentLoadOutIds
- [ ] AliveTime
- [ ] MissionTime
- [ ] Missions
- [ ] CompletedAlerts
- [ ] LastRegionPlayed
- [ ] GameModeId
- [ ] hosts
- [ ] ChallengeProgress
- [ ] SeasonChallengeHistory
- [ ] PS
- [ ] ActiveDojoColorResearch
- [ ] RewardInfo
- [ ] ReceivedCeremonyMsg
- [ ] LastCeremonyResetDate
- [ ] MissionPTS
- [ ] RepHash
- [ ] EndOfMatchUpload
- [ ] ObjectiveReached
- [ ] FpsAvg
- [ ] FpsMin
- [ ] FpsMax
- [ ] FpsSamples
*/
const missionInventoryUpdateController: RequestHandler = async (req, res) => {
fs.writeFile("./tmp/test", req.body, function(err) {
if(err) {
return console.log(err);
}
});
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);
const missionInventoryUpdateController: RequestHandler = (_req, res) => {
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

@ -1,5 +1,5 @@
import { Model, Schema, Types, model } from "mongoose"; import { Model, Schema, Types, model } from "mongoose";
import { FlavourItem, IInventoryDatabase } from "../types/inventoryTypes/inventoryTypes"; import { FlavourItem, RawUpgrade, MiscItem, IInventoryDatabase } from "../types/inventoryTypes/inventoryTypes";
import { Oid } from "../types/commonTypes"; import { Oid } from "../types/commonTypes";
import { ISuitDatabase, ISuitDocument } from "@/src/types/inventoryTypes/SuitTypes"; import { ISuitDatabase, ISuitDocument } from "@/src/types/inventoryTypes/SuitTypes";
import { IWeaponDatabase } from "@/src/types/inventoryTypes/weaponTypes"; import { IWeaponDatabase } from "@/src/types/inventoryTypes/weaponTypes";
@ -334,6 +334,8 @@ type InventoryDocumentProps = {
Pistols: Types.DocumentArray<IWeaponDatabase>; Pistols: Types.DocumentArray<IWeaponDatabase>;
Melee: Types.DocumentArray<IWeaponDatabase>; Melee: Types.DocumentArray<IWeaponDatabase>;
FlavourItems: Types.DocumentArray<FlavourItem>; FlavourItems: Types.DocumentArray<FlavourItem>;
RawUpgrades: Types.DocumentArray<RawUpgrade>;
MiscItems: Types.DocumentArray<MiscItem>;
}; };
type InventoryModelType = Model<IInventoryDatabase, {}, InventoryDocumentProps>; type InventoryModelType = Model<IInventoryDatabase, {}, InventoryDocumentProps>;

View File

@ -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 } from "@/src/types/inventoryTypes/inventoryTypes"; import { FlavourItem, RawUpgrade, MiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
const createInventory = async (accountOwnerId: Types.ObjectId) => { const createInventory = async (accountOwnerId: Types.ObjectId) => {
try { try {
@ -106,4 +106,36 @@ 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> => {
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 });
}
});
await inventory.save();
};
export const addMiscItems = async (miscItems: MiscItem[], accountId: string): Promise<void> => {
const inventory = await getInventory(accountId);
miscItems?.forEach(item => {
const { ItemCount, ItemType } = item;
const existingItemIndex = inventory.MiscItems.findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) {
inventory.MiscItems[existingItemIndex].ItemCount += ItemCount;
inventory.markModified('MiscItems.' + existingItemIndex + '.ItemCount');
} else {
inventory.MiscItems.push({ ItemCount, ItemType });
}
});
await inventory.save();
};
export { createInventory, addPowerSuit }; export { createInventory, addPowerSuit };

View File

@ -377,6 +377,16 @@ export interface FlavourItem {
ItemType: string; ItemType: string;
} }
export interface RawUpgrade {
ItemCount: number;
ItemType: string;
}
export interface MiscItem {
ItemCount: number;
ItemType: string;
}
export interface CrewshipWeapon { export interface CrewshipWeapon {
PILOT: Pilot; PILOT: Pilot;
PORT_GUNS: PortGuns; PORT_GUNS: PortGuns;