Skip to content

Commit

Permalink
Merge pull request #15 from IntersectMBO/dev
Browse files Browse the repository at this point in the history
From Dev to QA - 12.11.2024
  • Loading branch information
nebojsajsimic authored Nov 12, 2024
2 parents 20de071 + e24f3dd commit 5792b18
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion backend/src/api/poll-vote/controllers/poll-vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 };
}
Expand Down

0 comments on commit 5792b18

Please sign in to comment.