only update user fields if they changed
This commit is contained in:
parent
1e3f47c11c
commit
5b717a2963
@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
### Fixed
|
||||
|
||||
- only update user fields in update mutation if they changed
|
||||
|
||||
### Security
|
||||
|
||||
## [1.0.0] - 2022-02-28
|
||||
|
||||
@ -16,15 +16,15 @@ export class UserUpdateService {
|
||||
}
|
||||
|
||||
async update(user: UserEntity, input: UserUpdateInput): Promise<UserEntity> {
|
||||
if (input.firstName !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'firstName')) {
|
||||
user.firstName = input.firstName
|
||||
}
|
||||
|
||||
if (input.lastName !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'lastName')) {
|
||||
user.lastName = input.lastName
|
||||
}
|
||||
|
||||
if (input.email !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'email')) {
|
||||
user.email = input.email
|
||||
user.emailVerified = false
|
||||
// TODO request email verification
|
||||
@ -34,15 +34,15 @@ export class UserUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
if (input.username !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'username')) {
|
||||
user.username = input.username
|
||||
}
|
||||
|
||||
if (input.roles !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'roles')) {
|
||||
user.roles = input.roles as rolesType
|
||||
}
|
||||
|
||||
if (input.language !== undefined) {
|
||||
if (this.shouldUpdate(input, user, 'language')) {
|
||||
user.language = input.language
|
||||
}
|
||||
|
||||
@ -54,4 +54,16 @@ export class UserUpdateService {
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
private shouldUpdate(
|
||||
input: UserUpdateInput,
|
||||
user: UserEntity,
|
||||
property: keyof UserUpdateInput
|
||||
): boolean {
|
||||
if (input[property] === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
return input[property] == user[property]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user