diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:09:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:12:14 +0200 |
commit | 16c016e8b1d5ca46343d3363f9a49e24c5d7c944 (patch) | |
tree | 157dfa22ac95bd76a411aaf78e4df17152530e1c /server/controllers/api/users/index.ts | |
parent | 9a320a06b663a2e02c3156a07135f75f9e987b11 (diff) | |
download | PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.gz PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.zst PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.zip |
Stricter models typing
Diffstat (limited to 'server/controllers/api/users/index.ts')
-rw-r--r-- | server/controllers/api/users/index.ts | 22 |
1 files changed, 14 insertions, 8 deletions
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) { | |||
323 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) | 323 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) |
324 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role | 324 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role |
325 | 325 | ||
326 | if (body.password !== undefined) userToUpdate.password = body.password | 326 | const keysToUpdate: (keyof UserUpdate)[] = [ |
327 | if (body.email !== undefined) userToUpdate.email = body.email | 327 | 'password', |
328 | if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified | 328 | 'email', |
329 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota | 329 | 'emailVerified', |
330 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily | 330 | 'videoQuota', |
331 | if (body.role !== undefined) userToUpdate.role = body.role | 331 | 'videoQuotaDaily', |
332 | if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags | 332 | 'role', |
333 | if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuth | 333 | 'adminFlags', |
334 | 'pluginAuth' | ||
335 | ] | ||
336 | |||
337 | for (const key of keysToUpdate) { | ||
338 | if (body[key] !== undefined) userToUpdate.set(key, body[key]) | ||
339 | } | ||
334 | 340 | ||
335 | const user = await userToUpdate.save() | 341 | const user = await userToUpdate.save() |
336 | 342 | ||