@@ -5,41 +5,11 @@ import { eq, count } from 'drizzle-orm'
55import type { AppEnv } from '../types'
66import { ensureUserExists } from './user.Service'
77import { 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-
348export 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