From e19864f3f49cdf1110db98d75939996b811f4708 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 18 May 2020 13:23:46 +0200 Subject: [PATCH] Avoid creation of duplicate entries --- src/controllers/SurveyController.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/SurveyController.ts b/src/controllers/SurveyController.ts index 848ed06..4e71575 100644 --- a/src/controllers/SurveyController.ts +++ b/src/controllers/SurveyController.ts @@ -59,6 +59,10 @@ export class SurveyController { if(!survey.allowNewChoices) h.error(401, "It is not possible to create new choices for this survey!"); + // Check if we are not creating a duplicate + if(survey.choices.find((c) => c.name.toLowerCase() == newChoice.toLowerCase()) != undefined) + h.error(401, "This choice already exists!"); + // Create the choice await SurveyHelper.CreateChoice(surveyID, newChoice);