From f6afdd48690351f03048286299b65d7d9469077a Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 3 Jan 2025 06:55:21 +0100 Subject: [PATCH] chore: add crewship to freestanding inventory --- src/services/inventoryService.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 272752c8..445fa091 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -143,11 +143,10 @@ export const addItem = async ( } }; } else if (ExportResources[typeName].productCategory == "CrewShips") { - return { - InventoryChanges: { - CrewShips: [await addCrewShip(typeName, accountId)] - } - }; + const inventory = await getInventory(accountId); + const inventoryChanges = addCrewShip(inventory, typeName); + await inventory.save(); + return { InventoryChanges: inventoryChanges }; } else { const miscItemChanges = [ { @@ -590,11 +589,15 @@ export const addSkin = async (typeName: string, accountId: string): Promise { - const inventory = await getInventory(accountId); +const addCrewShip = ( + inventory: TInventoryDatabaseDocument, + typeName: string, + inventoryChanges: IInventoryChanges = {} +): IInventoryChanges => { const index = inventory.CrewShips.push({ ItemType: typeName }) - 1; - const changedInventory = await inventory.save(); - return changedInventory.CrewShips[index].toJSON(); + inventoryChanges.CrewShips ??= []; + (inventoryChanges.CrewShips as object[]).push(inventory.CrewShips[index].toJSON()); + return inventoryChanges; }; const addGearExpByCategory = (