diff options
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r-- | server/middlewares/validators/users.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index adc67a046..840b9fc74 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { body, param } from 'express-validator' | 3 | import { body, param, query } from 'express-validator' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
@@ -256,12 +256,13 @@ const usersUpdateMeValidator = [ | |||
256 | 256 | ||
257 | const usersGetValidator = [ | 257 | const usersGetValidator = [ |
258 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), | 258 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), |
259 | query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), | ||
259 | 260 | ||
260 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 261 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
261 | logger.debug('Checking usersGet parameters', { parameters: req.params }) | 262 | logger.debug('Checking usersGet parameters', { parameters: req.params }) |
262 | 263 | ||
263 | if (areValidationErrors(req, res)) return | 264 | if (areValidationErrors(req, res)) return |
264 | if (!await checkUserIdExist(req.params.id, res)) return | 265 | if (!await checkUserIdExist(req.params.id, res, req.query.withStats)) return |
265 | 266 | ||
266 | return next() | 267 | return next() |
267 | } | 268 | } |
@@ -460,9 +461,9 @@ export { | |||
460 | 461 | ||
461 | // --------------------------------------------------------------------------- | 462 | // --------------------------------------------------------------------------- |
462 | 463 | ||
463 | function checkUserIdExist (idArg: number | string, res: express.Response) { | 464 | function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { |
464 | const id = parseInt(idArg + '', 10) | 465 | const id = parseInt(idArg + '', 10) |
465 | return checkUserExist(() => UserModel.loadById(id), res) | 466 | return checkUserExist(() => UserModel.loadById(id, withStats), res) |
466 | } | 467 | } |
467 | 468 | ||
468 | function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { | 469 | function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { |