From 76314386aeafdd6849b7b70c517779d6b2013473 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 27 Mar 2020 15:19:03 +0100 Subject: Add overview of a user's actions in user-edit (#2558) --- server/middlewares/validators/users.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'server/middlewares') 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 @@ import * as Bluebird from 'bluebird' import * as express from 'express' -import { body, param } from 'express-validator' +import { body, param, query } from 'express-validator' import { omit } from 'lodash' import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' import { @@ -256,12 +256,13 @@ const usersUpdateMeValidator = [ const usersGetValidator = [ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), + query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersGet parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await checkUserIdExist(req.params.id, res)) return + if (!await checkUserIdExist(req.params.id, res, req.query.withStats)) return return next() } @@ -460,9 +461,9 @@ export { // --------------------------------------------------------------------------- -function checkUserIdExist (idArg: number | string, res: express.Response) { +function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { const id = parseInt(idArg + '', 10) - return checkUserExist(() => UserModel.loadById(id), res) + return checkUserExist(() => UserModel.loadById(id, withStats), res) } function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { -- cgit v1.2.3