From f9afdc7a2b16ba1b9665ea36d6de8c1b28a9c61f Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 15 Jun 2024 01:19:21 +0200 Subject: [PATCH] Add InventorySlot enum --- src/controllers/api/inventorySlotsController.ts | 3 ++- src/services/inventoryService.ts | 11 ++++++----- src/types/inventoryTypes/inventoryTypes.ts | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/controllers/api/inventorySlotsController.ts b/src/controllers/api/inventorySlotsController.ts index 154a8da0..b026077b 100644 --- a/src/controllers/api/inventorySlotsController.ts +++ b/src/controllers/api/inventorySlotsController.ts @@ -2,6 +2,7 @@ import { getAccountIdForRequest } from "@/src/services/loginService"; import { updateCurrency } from "@/src/services/inventoryService"; import { RequestHandler } from "express"; import { updateSlots } from "@/src/services/inventoryService"; +import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; /* loadout slots are additionally purchased slots only @@ -27,7 +28,7 @@ export const inventorySlotsController: RequestHandler = async (req, res) => { //TODO: check which slot was purchased because pvpBonus is also possible const currencyChanges = await updateCurrency(20, true, accountId); - await updateSlots(accountId, "PveBonusLoadoutBin", 1, 1); + await updateSlots(accountId, InventorySlot.PVE_LOADOUTS, 1, 1); //console.log({ InventoryChanges: currencyChanges }, " added loadout changes:"); diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 1aba547e..f21ea25a 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -14,7 +14,8 @@ import { IMission, IRawUpgrade, ISeasonChallengeHistory, - ITypeCount + ITypeCount, + InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; import { IGenericUpdate } from "../types/genericUpdate"; import { @@ -74,7 +75,7 @@ export const addItem = async ( case "Powersuits": if (typeName.includes("EntratiMech")) { const mechSuit = await addMechSuit(typeName, accountId); - await updateSlots(accountId, "MechBin", 0, 1); + await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1); logger.debug("mech suit", mechSuit); return { InventoryChanges: { @@ -88,7 +89,7 @@ export const addItem = async ( }; } const suit = await addPowerSuit(typeName, accountId); - await updateSlots(accountId, "SuitBin", 0, 1); + await updateSlots(accountId, InventorySlot.SUITS, 0, 1); return { InventoryChanges: { SuitBin: { @@ -102,7 +103,7 @@ export const addItem = async ( case "Weapons": const weaponType = getWeaponType(typeName); const weapon = await addWeapon(weaponType, typeName, accountId); - await updateSlots(accountId, "WeaponBin", 0, 1); + await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1); return { InventoryChanges: { WeaponBin: { count: 1, platinum: 0, Slots: -1 }, @@ -127,7 +128,7 @@ export const addItem = async ( case "Sentinels": // TOOD: Sentinels should also grant their DefaultUpgrades & SentinelWeapon. const sentinel = await addSentinel(typeName, accountId); - await updateSlots(accountId, "SentinelBin", 0, 1); + await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1); return { InventoryChanges: { SentinelBin: { count: 1, platinum: 0, Slots: -1 }, diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 66f863ee..3bc903cd 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -419,6 +419,14 @@ export interface ICrewShipHarnessConfig { Upgrades?: string[]; } +export enum InventorySlot { + SUITS = "SuitBin", + WEAPONS = "WeaponBin", + MECHSUITS = "MechBin", + PVE_LOADOUTS = "PveBonusLoadoutBin", + SENTINELS = "SentinelBin" +} + export interface ISlots { Extra: number; // can be undefined, but not if used via mongoose Slots: number;