X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fbulk.ts;h=a1cea8032e3dcbc68c824e15d92123029a4d9f7f;hb=564b9b55976873d87e669ace916f037b72fe2865;hp=cfb16d352997500db4239a4e1aae7a20579d96b6;hpb=2d53be0267acc49cda46707b885096193a1f4e9c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts index cfb16d352..a1cea8032 100644 --- a/server/middlewares/validators/bulk.ts +++ b/server/middlewares/validators/bulk.ts @@ -1,21 +1,17 @@ -import * as express from 'express' +import express from 'express' import { body } from 'express-validator' import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' -import { doesAccountNameWithHostExist } from '@server/helpers/middlewares' -import { UserRight } from '@shared/models' +import { HttpStatusCode, UserRight } from '@shared/models' import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { areValidationErrors, doesAccountNameWithHostExist } from './shared' const bulkRemoveCommentsOfValidator = [ - body('accountName').exists().withMessage('Should have an account name with host'), + body('accountName') + .exists(), body('scope') - .custom(isBulkRemoveCommentsOfScopeValid).withMessage('Should have a valid scope'), + .custom(isBulkRemoveCommentsOfScopeValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body }) - if (areValidationErrors(req, res)) return if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return @@ -23,9 +19,9 @@ const bulkRemoveCommentsOfValidator = [ const body = req.body as BulkRemoveCommentsOfBody if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) { - return res.status(HttpStatusCode.FORBIDDEN_403) - .json({ - error: 'User cannot remove any comments of this instance.' + return res.fail({ + status: HttpStatusCode.FORBIDDEN_403, + message: 'User cannot remove any comments of this instance.' }) }