Skip to content

Commit 3fcb46d

Browse files
authored
Revert "timimgs fix"
1 parent 844d309 commit 3fcb46d

2 files changed

Lines changed: 5 additions & 38 deletions

File tree

apps/api/src/controllers/vote.Controller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { submitVote } from '../services/vote.Service'
55

66
export const createVote = async (c: Context<AppEnv>) => {
77
const userId = c.get('userId')
8-
8+
99
let body: VoteRequest
1010
try {
1111
body = await c.req.json()
@@ -18,14 +18,14 @@ export const createVote = async (c: Context<AppEnv>) => {
1818
if (typeof stallId !== 'number' || typeof rating !== 'number') {
1919
return c.json({ success: false, message: 'stallId and rating must be numbers' }, 400)
2020
}
21-
21+
2222
if (rating < 0 || rating > 10) {
2323
return c.json({ success: false, message: 'rating must be between 0 and 10' }, 400)
2424
}
2525

2626
try {
2727
const progressCount = await submitVote(c.env, userId, body)
28-
28+
2929
const response: VoteResponse = {
3030
success: true,
3131
message: 'Vote submitted successfully',
@@ -37,9 +37,6 @@ export const createVote = async (c: Context<AppEnv>) => {
3737
if (e.message === 'Already voted') {
3838
return c.json({ success: false, message: 'Already voted' }, 400)
3939
}
40-
if (e.message === 'Voting is currently closed') {
41-
return c.json({ success: false, message: 'Voting is currently closed' }, 403)
42-
}
4340
return c.json({ success: false, message: 'Internal Server Error' }, 500)
4441
}
4542
}

apps/api/src/services/vote.Service.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,11 @@ import { eq, count } from 'drizzle-orm'
55
import type { AppEnv } from '../types'
66
import { ensureUserExists } from './user.Service'
77
import { refreshStallAggregates } from './stalls.Service'
8-
function isVotingOpen(): boolean {
9-
const istOffset = 5.5 * 60 * 60 * 1000;
10-
const istTime = new Date(Date.now() + istOffset);
11-
12-
const year = istTime.getUTCFullYear();
13-
const month = istTime.getUTCMonth() + 1;
14-
const day = istTime.getUTCDate();
15-
16-
if (year !== 2026 || month !== 3) return false;
17-
18-
const timeInMinutes = istTime.getUTCHours() * 60 + istTime.getUTCMinutes();
19-
const startMins = 9 * 60 + 30; // 9:30 AM (570)
20-
21-
if (day === 28) {
22-
const endMins = 22 * 60; // 10:00 PM (1320)
23-
return timeInMinutes >= startMins && timeInMinutes <= endMins;
24-
}
25-
26-
if (day === 29) {
27-
const endMins = 12 * 60; // 12:00 PM (720)
28-
return timeInMinutes >= startMins && timeInMinutes <= endMins;
29-
}
30-
31-
return false;
32-
}
33-
348
export const submitVote = async (
359
env: AppEnv['Bindings'],
3610
userId: string,
3711
vote: VoteRequest
3812
) => {
39-
if (!isVotingOpen()) {
40-
throw new Error('Voting is currently closed');
41-
}
42-
4313
const { stallId, rating } = vote
4414
const ormDb = getDb(env.DB)
4515

@@ -79,11 +49,11 @@ export const submitVote = async (
7949
.select({ stallId: ratings.stallId })
8050
.from(ratings)
8151
.where(eq(ratings.userId, userId));
82-
52+
8353
const stallIds = userRatings
8454
.map(r => r.stallId)
8555
.filter((id): id is number => id !== null);
86-
56+
8757
await refreshStallAggregates(env.DB, stallIds);
8858
} else {
8959
// Normal vote (could be qualified or not, but only this stall is affected)

0 commit comments

Comments
 (0)