fix: using ILoadoutConfigClient to write to database (#190)

This commit is contained in:
Sainan 2024-05-07 20:38:44 +02:00 committed by GitHub
parent a8ea8d1364
commit 7b3f9b3015
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ import {
IItemEntry, IItemEntry,
ILoadoutClient, ILoadoutClient,
ILoadoutEntry, ILoadoutEntry,
ILoadoutConfigDatabase,
IOperatorConfigEntry, IOperatorConfigEntry,
ISaveLoadoutRequestNoUpgradeVer ISaveLoadoutRequestNoUpgradeVer
} from "@/src/types/saveLoadoutTypes"; } from "@/src/types/saveLoadoutTypes";
@ -86,10 +87,14 @@ export const handleInventoryItemConfigChange = async (
loadout => loadout._id.toString() === loadoutId 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 no config with this id exists, create a new one
if (!oldLoadoutConfig) { if (!oldLoadoutConfig) {
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
//save the new object id and assign it for every ffff return at the end //save the new object id and assign it for every ffff return at the end
if (ItemId.$oid === "ffffffffffffffffffffffff") { if (ItemId.$oid === "ffffffffffffffffffffffff") {
if (!newLoadoutId) { if (!newLoadoutId) {
@ -99,10 +104,7 @@ export const handleInventoryItemConfigChange = async (
continue; continue;
} }
loadout[loadoutSlot].push({ loadout[loadoutSlot].push(loadoutConfigDatabase);
_id: ItemId.$oid,
...loadoutConfigItemIdRemoved
});
continue; continue;
} }
@ -111,7 +113,7 @@ export const handleInventoryItemConfigChange = async (
throw new Error("loadout index not found"); throw new Error("loadout index not found");
} }
loadout[loadoutSlot][loadoutIndex].overwrite(loadoutConfig); loadout[loadoutSlot][loadoutIndex].overwrite(loadoutConfigDatabase);
} }
} }
await loadout.save(); await loadout.save();