Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/api/src/controllers/vote.Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { submitVote } from '../services/vote.Service'

export const createVote = async (c: Context<AppEnv>) => {
const userId = c.get('userId')

let body: VoteRequest
try {
body = await c.req.json()
Expand All @@ -18,14 +18,14 @@ export const createVote = async (c: Context<AppEnv>) => {
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',
Expand All @@ -37,6 +37,9 @@ export const createVote = async (c: Context<AppEnv>) => {
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)
}
}
Loading