Skip to content

Commit

Permalink
- Added check for already existing active pool [Bug #2507] IntersectM…
Browse files Browse the repository at this point in the history
…BO/govtool#2507

- Fixed buf #2508 Unable to vote after opening new voting pool
  • Loading branch information
nebojsajsimic committed Dec 25, 2024
1 parent 3f396de commit 541bf9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 2 additions & 4 deletions backend/src/api/poll-vote/controllers/poll-vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ module.exports = createCoreController(
async create(ctx) {
const { data } = ctx?.request?.body;
const { vote_result: voteResult, poll_id: pollId } = data;

const user = ctx?.state?.user;

if (!user) {
return ctx.badRequest(null, 'User is required');
}
Expand Down Expand Up @@ -51,7 +49,7 @@ module.exports = createCoreController(
user_id: user?.id
},
{
poll_Id: pollId
poll_id: pollId
}
]}
})
Expand Down Expand Up @@ -261,4 +259,4 @@ module.exports = createCoreController(
}
},
})
);
);
6 changes: 5 additions & 1 deletion backend/src/api/poll/controllers/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = createCoreController('api::poll.poll', ({ strapi }) => ({
{
return ctx.badRequest(null, 'User is not owner of this proposal');
}

const currentActivePool = await strapi.entityService.findMany("api::poll.poll",{filters:{$and:[{proposal_id:data.proposal_id},{is_poll_active:true}]},limit:1});
if(currentActivePool.length > 0)
{
return ctx.badRequest(null, 'There is already an active pool for this proposal');
}
const newPool = await strapi.entityService.create("api::poll.poll",{data:data});
return this.transformResponse(newPool);
}
Expand Down

0 comments on commit 541bf9b

Please sign in to comment.