From 40a4846859be41c33fdd02a75cb7ecc4df9578f5 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 7 May 2024 17:47:09 +0200 Subject: [PATCH] fix: using ILoadoutConfigClient to write to database This was causing unequipping weapons to fail again due to newer mongoose version. --- src/services/saveLoadoutService.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/saveLoadoutService.ts b/src/services/saveLoadoutService.ts index 826a8548..c08a47b3 100644 --- a/src/services/saveLoadoutService.ts +++ b/src/services/saveLoadoutService.ts @@ -2,6 +2,7 @@ import { IItemEntry, ILoadoutClient, ILoadoutEntry, + ILoadoutConfigDatabase, IOperatorConfigEntry, ISaveLoadoutRequestNoUpgradeVer } from "@/src/types/saveLoadoutTypes"; @@ -86,10 +87,14 @@ export const handleInventoryItemConfigChange = async ( loadout => loadout._id.toString() === loadoutId ); + const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig; + const loadoutConfigDatabase: ILoadoutConfigDatabase = { + _id: new Types.ObjectId(ItemId.$oid), + ...loadoutConfigItemIdRemoved + }; + // if no config with this id exists, create a new one if (!oldLoadoutConfig) { - const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig; - //save the new object id and assign it for every ffff return at the end if (ItemId.$oid === "ffffffffffffffffffffffff") { if (!newLoadoutId) { @@ -99,10 +104,7 @@ export const handleInventoryItemConfigChange = async ( continue; } - loadout[loadoutSlot].push({ - _id: ItemId.$oid, - ...loadoutConfigItemIdRemoved - }); + loadout[loadoutSlot].push(loadoutConfigDatabase); continue; } @@ -111,7 +113,7 @@ export const handleInventoryItemConfigChange = async ( throw new Error("loadout index not found"); } - loadout[loadoutSlot][loadoutIndex].overwrite(loadoutConfig); + loadout[loadoutSlot][loadoutIndex].overwrite(loadoutConfigDatabase); } } await loadout.save(); -- 2.47.2