From 52aa00dd134af2f50b0745c7bef93b033d08efc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 9 Mar 2026 19:54:50 +0100 Subject: [PATCH] fix: embed DECAY_LAMBDA as SQL literal to avoid pg type inference failure PostgreSQL cannot resolve the type of a parameterized $1 = 0.005 in -$1 * EXTRACT(EPOCH ...) and fails with an operator type error. Using sql.raw() embeds the constant directly in the query string so userId is the only parameter. Co-Authored-By: Claude Sonnet 4.6 --- packages/backend/src/lib/gamification.ts | 2 +- packages/backend/src/queues/workers/gamification.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/lib/gamification.ts b/packages/backend/src/lib/gamification.ts index dccc964..a6c3a51 100644 --- a/packages/backend/src/lib/gamification.ts +++ b/packages/backend/src/lib/gamification.ts @@ -62,7 +62,7 @@ export async function revokePoints( export async function calculateWeightedScore(db: DB, userId: string): Promise { const result = await db.execute(sql` SELECT SUM( - points * EXP(-${DECAY_LAMBDA} * EXTRACT(EPOCH FROM (NOW() - date_created)) / 86400) + points * EXP(${sql.raw(String(-DECAY_LAMBDA))} * EXTRACT(EPOCH FROM (NOW() - date_created)) / 86400) ) as weighted_score FROM user_points WHERE user_id = ${userId} diff --git a/packages/backend/src/queues/workers/gamification.ts b/packages/backend/src/queues/workers/gamification.ts index 13ca5da..1bd1889 100644 --- a/packages/backend/src/queues/workers/gamification.ts +++ b/packages/backend/src/queues/workers/gamification.ts @@ -17,7 +17,10 @@ export function startGamificationWorker(): Worker { "gamification", async (bullJob) => { const data = bullJob.data as GamificationJobData; - log.info({ jobId: bullJob.id, job: data.job, userId: data.userId }, "Processing gamification job"); + log.info( + { jobId: bullJob.id, job: data.job, userId: data.userId }, + "Processing gamification job", + ); switch (data.job) { case "awardPoints":