From 8c90d422c297d37c2b49ef76a7f02a1c3eb0c5c5 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 11 Mar 2024 12:21:59 +0000 Subject: [PATCH] Update to update self endpoint to make remove distinct flow for appFavourites --- .../worker/src/api/controllers/global/self.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/worker/src/api/controllers/global/self.ts b/packages/worker/src/api/controllers/global/self.ts index 15fe84b021..a3c001de03 100644 --- a/packages/worker/src/api/controllers/global/self.ts +++ b/packages/worker/src/api/controllers/global/self.ts @@ -164,23 +164,21 @@ export async function updateSelf( const update = ctx.request.body let user = await userSdk.db.getUser(ctx.user._id!) + let requestAppFavourites: string[] = [...(update.appFavourites || [])] + let updatedAppFavourites: string[] | undefined if ("appFavourites" in update) { const appIds: string[] = processUserAppFavourites( user, - update.appFavourites + requestAppFavourites ) - const validAppIds: string[] = await syncAppFavourites(appIds) + updatedAppFavourites = await syncAppFavourites(appIds) + } - user = { - ...user, - appFavourites: validAppIds, - } - } else { - user = { - ...user, - ...update, - } + user = { + ...user, + ...update, + ...(updatedAppFavourites ? { appFavourites: updatedAppFavourites } : {}), } user = await userSdk.db.save(user, { requirePassword: false })