+const usersBlockingValidator = [
+ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
+ body('reason').optional().custom(isUserBlockedReasonValid).withMessage('Should have a valid blocking reason'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersBlocking parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await checkUserIdExist(req.params.id, res)) return
+
+ const user = res.locals.user
+ if (user.username === 'root') {
+ return res.status(400)
+ .send({ error: 'Cannot block the root user' })
+ .end()
+ }
+
+ return next()
+ }
+]
+
+const deleteMeValidator = [
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ const user: UserModel = res.locals.oauth.token.User
+ if (user.username === 'root') {
+ return res.status(400)
+ .send({ error: 'You cannot delete your root account.' })
+ .end()
+ }
+
+ return next()
+ }
+]
+