diff --git a/apps/api/src/controllers/vote.Controller.ts b/apps/api/src/controllers/vote.Controller.ts index 4fee4bf..5d0e7e5 100644 --- a/apps/api/src/controllers/vote.Controller.ts +++ b/apps/api/src/controllers/vote.Controller.ts @@ -5,7 +5,7 @@ import { submitVote } from '../services/vote.Service' export const createVote = async (c: Context) => { const userId = c.get('userId') - + let body: VoteRequest try { body = await c.req.json() @@ -18,14 +18,14 @@ export const createVote = async (c: Context) => { if (typeof stallId !== 'number' || typeof rating !== 'number') { return c.json({ success: false, message: 'stallId and rating must be numbers' }, 400) } - + if (rating < 0 || rating > 10) { return c.json({ success: false, message: 'rating must be between 0 and 10' }, 400) } try { const progressCount = await submitVote(c.env, userId, body) - + const response: VoteResponse = { success: true, message: 'Vote submitted successfully', @@ -37,6 +37,9 @@ export const createVote = async (c: Context) => { if (e.message === 'Already voted') { return c.json({ success: false, message: 'Already voted' }, 400) } + if (e.message === 'Voting is currently closed') { + return c.json({ success: false, message: 'Voting is currently closed' }, 403) + } return c.json({ success: false, message: 'Internal Server Error' }, 500) } }