From 1eb9ac82174462807c0417152c34fca4e73034d7 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 28 Dec 2022 21:07:04 -0600 Subject: [PATCH] fix(server) Cannot change first time password due to null in first and last name payload (#1205) * fix(server) Cannot change first time password due to null in first and last name payload * Added error message for form on the web --- .../apps/immich/src/api-v1/user/user.core.ts | 16 +++++++- .../components/forms/create-user-form.svelte | 40 +++++++++++++------ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/server/apps/immich/src/api-v1/user/user.core.ts b/server/apps/immich/src/api-v1/user/user.core.ts index a2dec23a4b..c2d99aedb4 100644 --- a/server/apps/immich/src/api-v1/user/user.core.ts +++ b/server/apps/immich/src/api-v1/user/user.core.ts @@ -35,11 +35,25 @@ export class UserCore { } } + const user = await this.userRepository.get(id); + if (!user) { + throw new NotFoundException('User not found'); + } + try { if (dto.password) { dto.password = await hash(dto.password, SALT_ROUNDS); } - return this.userRepository.update(id, dto); + + user.password = dto.password ?? user.password; + user.email = dto.email ?? user.email; + user.firstName = dto.firstName ?? user.firstName; + user.lastName = dto.lastName ?? user.lastName; + user.isAdmin = dto.isAdmin ?? user.isAdmin; + user.shouldChangePassword = dto.shouldChangePassword ?? user.shouldChangePassword; + user.profileImagePath = dto.profileImagePath ?? user.profileImagePath; + + return this.userRepository.update(id, user); } catch (e) { Logger.error(e, 'Failed to update user info'); throw new InternalServerErrorException('Failed to update user info'); diff --git a/web/src/lib/components/forms/create-user-form.svelte b/web/src/lib/components/forms/create-user-form.svelte index 125bb192eb..d7ebac843e 100644 --- a/web/src/lib/components/forms/create-user-form.svelte +++ b/web/src/lib/components/forms/create-user-form.svelte @@ -1,6 +1,10 @@