From 8085b40af862b1815619c6c0757cae37c76592d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 9 Mar 2026 19:52:03 +0100 Subject: [PATCH] fix: use NOW() in weighted score query instead of JS Date parameter Passing a JS Date to a Drizzle sql template serializes it as a locale string (e.g. "Mon Mar 09 2026 19:51:22 GMT+0100") which PostgreSQL cannot parse as timestamptz, causing the gamification worker to fail. Co-Authored-By: Claude Sonnet 4.6 --- packages/backend/src/lib/gamification.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/backend/src/lib/gamification.ts b/packages/backend/src/lib/gamification.ts index b26457e..dccc964 100644 --- a/packages/backend/src/lib/gamification.ts +++ b/packages/backend/src/lib/gamification.ts @@ -60,10 +60,9 @@ export async function revokePoints( } export async function calculateWeightedScore(db: DB, userId: string): Promise { - const now = new Date(); const result = await db.execute(sql` SELECT SUM( - points * EXP(-${DECAY_LAMBDA} * EXTRACT(EPOCH FROM (${now}::timestamptz - date_created)) / 86400) + points * EXP(-${DECAY_LAMBDA} * EXTRACT(EPOCH FROM (NOW() - date_created)) / 86400) ) as weighted_score FROM user_points WHERE user_id = ${userId}