From 16c016e8b1d5ca46343d3363f9a49e24c5d7c944 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 12 May 2021 14:09:04 +0200 Subject: Stricter models typing --- server/controllers/api/users/index.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'server/controllers/api/users/index.ts') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index c655d1648..f384f0f28 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -323,14 +323,20 @@ async function updateUser (req: express.Request, res: express.Response) { const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) const roleChanged = body.role !== undefined && body.role !== userToUpdate.role - if (body.password !== undefined) userToUpdate.password = body.password - if (body.email !== undefined) userToUpdate.email = body.email - if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified - if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota - if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily - if (body.role !== undefined) userToUpdate.role = body.role - if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags - if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuth + const keysToUpdate: (keyof UserUpdate)[] = [ + 'password', + 'email', + 'emailVerified', + 'videoQuota', + 'videoQuotaDaily', + 'role', + 'adminFlags', + 'pluginAuth' + ] + + for (const key of keysToUpdate) { + if (body[key] !== undefined) userToUpdate.set(key, body[key]) + } const user = await userToUpdate.save() -- cgit v1.2.3