From 0ae0166d494d21688d6f197a197b80ce8cb6efcf Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 18 May 2020 13:30:48 +0200 Subject: [PATCH] Auto-block choices creation if the maximum is reached --- src/controllers/SurveyController.ts | 6 +++++- src/helpers/SurveyHelper.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controllers/SurveyController.ts b/src/controllers/SurveyController.ts index 4e71575..f1742d2 100644 --- a/src/controllers/SurveyController.ts +++ b/src/controllers/SurveyController.ts @@ -1,6 +1,6 @@ import { Survey, SurveyChoice } from "../entities/Survey"; import { RequestHandler } from "../entities/RequestHandler"; -import { SurveyHelper } from "../helpers/SurveyHelper"; +import { SurveyHelper, MAXIMUM_NUMBER_SURVEY_CHOICES } from "../helpers/SurveyHelper"; import { SurveyResponse } from "../entities/SurveyResponse"; import { PostAccessLevel } from "../entities/Post"; @@ -66,6 +66,10 @@ export class SurveyController { // Create the choice await SurveyHelper.CreateChoice(surveyID, newChoice); + // Auto-block creation of new choices if limit is reached + if(survey.choices.length + 1 >= MAXIMUM_NUMBER_SURVEY_CHOICES) + await SurveyHelper.BlockNewChoicesCreation(surveyID); + h.success(); } diff --git a/src/helpers/SurveyHelper.ts b/src/helpers/SurveyHelper.ts index 6833839..8fcb998 100644 --- a/src/helpers/SurveyHelper.ts +++ b/src/helpers/SurveyHelper.ts @@ -25,6 +25,11 @@ const SURVEY_CHOICES_TABLE = "sondage_choix"; */ const SURVEY_RESPONSE_TABLE = "sondage_reponse"; +/** + * Maximum number of choices for a survey + */ +export const MAXIMUM_NUMBER_SURVEY_CHOICES = 20; + /** * Survey helper */