From 9e7e0fc6ff3b3730975cd1d3219316b7bd936a6a Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 6 Sep 2022 17:02:35 +0200 Subject: [PATCH] checking if inventory is undefined --- backend/src/dal/user.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/src/dal/user.ts b/backend/src/dal/user.ts index ccbc8fe79..e03234af5 100644 --- a/backend/src/dal/user.ts +++ b/backend/src/dal/user.ts @@ -730,16 +730,19 @@ export async function updateProfile( value === undefined || (_.isPlainObject(value) && _.isEmpty(value)) ); + const updates = { + $set: { + ...profileUpdates, + inventory, + }, + }; + if (inventory === undefined) delete updates.$set.inventory; + await getUsersCollection().updateOne( { uid, }, - { - $set: { - ...profileUpdates, - inventory, - }, - } + updates ); }