diff --git a/backend/src/api/poll-vote/controllers/poll-vote.js b/backend/src/api/poll-vote/controllers/poll-vote.js index 92e3f6a..8e82cc1 100644 --- a/backend/src/api/poll-vote/controllers/poll-vote.js +++ b/backend/src/api/poll-vote/controllers/poll-vote.js @@ -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'); } @@ -51,7 +49,7 @@ module.exports = createCoreController( user_id: user?.id }, { - poll_Id: pollId + poll_id: pollId } ]} }) @@ -261,4 +259,4 @@ module.exports = createCoreController( } }, }) -); +); \ No newline at end of file diff --git a/backend/src/api/poll/controllers/poll.js b/backend/src/api/poll/controllers/poll.js index 8fb9887..af5413f 100644 --- a/backend/src/api/poll/controllers/poll.js +++ b/backend/src/api/poll/controllers/poll.js @@ -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); }