Update to update self endpoint to make remove distinct flow for appFavourites

This commit is contained in:
Dean 2024-03-11 12:21:59 +00:00
parent e3fba2aa05
commit 8c90d422c2
1 changed files with 9 additions and 11 deletions

View File

@ -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 })