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 */