aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts9
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as express from 'express' 2import * as express from 'express'
3import { body, param } from 'express-validator' 3import { body, param, query } from 'express-validator'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
6import { 6import {
@@ -256,12 +256,13 @@ const usersUpdateMeValidator = [
256 256
257const usersGetValidator = [ 257const 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
463function checkUserIdExist (idArg: number | string, res: express.Response) { 464function 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
468function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { 469function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) {