From 6e842cc391a34273792f23b86d6d4242d31ae7d7 Mon Sep 17 00:00:00 2001 From: nebojsajsimic <6024893+nebojsajsimic@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:11:57 +0100 Subject: [PATCH] bugfix #2356 --- .../api/poll-vote/controllers/poll-vote.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/src/api/poll-vote/controllers/poll-vote.js b/backend/src/api/poll-vote/controllers/poll-vote.js index bb27168..92e3f6a 100644 --- a/backend/src/api/poll-vote/controllers/poll-vote.js +++ b/backend/src/api/poll-vote/controllers/poll-vote.js @@ -44,6 +44,25 @@ module.exports = createCoreController( }; try { + // Check if vote already exist + try{ + const findVote = await strapi.entityService.findMany("api::poll-vote.poll-vote",{ + filters:{$and:[{ + user_id: user?.id + }, + { + poll_Id: pollId + } + ]} + }) + if(findVote?.length >0){ + return ctx.badRequest(null, "Poll vote for this user already exist"); + } + } + catch(error){ + ctx.status = 500; + ctx.body = { error: error, message: error.message }; + } // Create the Poll Vote try { pollVote = await strapi.entityService.create( @@ -111,7 +130,6 @@ module.exports = createCoreController( // Global error catch } catch (error) { pollVote && (await deletePollVote()); - ctx.status = 500; ctx.body = { error: error, message: error.message }; }