add max length validations for summary in challenge create and update… (#14053)

* add max length validations for summary in challenge create and update controllers

* Add validation to group APIs

* fix lint errors

* add validation to group plan

* fix imports

* add tests

* add max length validations for summary in challenge create and update controllers

* Add validation to group APIs

* fix lint errors

* add validation to group plan

* fix imports

* add tests

* lint checks
This commit is contained in:
Nishant Jain
2022-07-23 01:54:24 +05:30
committed by GitHub
parent 8e717de039
commit 8070486def
7 changed files with 71 additions and 1 deletions

View File

@@ -30,6 +30,10 @@ import {
} from '../../libs/challenges';
import apiError from '../../libs/apiError';
import common from '../../../common';
const { MAX_SUMMARY_SIZE_FOR_CHALLENGES } = common.constants;
const api = {};
/**
@@ -200,6 +204,7 @@ api.createChallenge = {
const { user } = res.locals;
req.checkBody('group', apiError('groupIdRequired')).notEmpty();
req.checkBody('summary', apiError('summaryLengthExceedsMax')).isLength({ max: MAX_SUMMARY_SIZE_FOR_CHALLENGES });
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
@@ -707,6 +712,7 @@ api.updateChallenge = {
middlewares: [authWithHeaders()],
async handler (req, res) {
req.checkParams('challengeId', res.t('challengeIdRequired')).notEmpty().isUUID();
req.checkBody('summary', apiError('summaryLengthExceedsMax')).isLength({ max: MAX_SUMMARY_SIZE_FOR_CHALLENGES });
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;