From 6e6c07eb025ffb9a0d9825c85291787ed403a4d8 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 3 Jan 2025 06:58:29 +0100 Subject: [PATCH] chore: add skin to freestanding inventory --- src/services/inventoryService.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 445fa091..bb555a97 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -164,11 +164,10 @@ export const addItem = async ( } } if (typeName in ExportCustoms) { - return { - InventoryChanges: { - WeaponSkins: [await addSkin(typeName, accountId)] - } - }; + const inventory = await getInventory(accountId); + const inventoryChanges = addSkin(inventory, typeName); + await inventory.save(); + return { InventoryChanges: inventoryChanges }; } if (typeName in ExportFlavour) { return { @@ -582,11 +581,17 @@ export const addCustomization = async (customizatonName: string, accountId: stri return changedInventory.FlavourItems[flavourItemIndex].toJSON(); }; -export const addSkin = async (typeName: string, accountId: string): Promise => { - const inventory = await getInventory(accountId); +export const addSkin = ( + inventory: TInventoryDatabaseDocument, + typeName: string, + inventoryChanges: IInventoryChanges = {} +): IInventoryChanges => { const index = inventory.WeaponSkins.push({ ItemType: typeName }) - 1; - const changedInventory = await inventory.save(); - return changedInventory.WeaponSkins[index].toJSON() as object as IWeaponSkinClient; + inventoryChanges.WeaponSkins ??= []; + (inventoryChanges.WeaponSkins as IWeaponSkinClient[]).push( + inventory.WeaponSkins[index].toJSON() + ); + return inventoryChanges; }; const addCrewShip = (