From cc693d8be703d45d2fee2feb98f7b9b4b7ed27d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 9 Mar 2026 20:04:20 +0100 Subject: [PATCH] fix: prevent achievement points from being re-awarded on republish Once an achievement is unlocked, preserve date_unlocked permanently instead of clearing it to null when the user drops below the threshold (e.g. on unpublish). This prevents the wasUnlocked check from returning false on republish, which was causing achievement points to be re-awarded on every publish/unpublish cycle. Co-Authored-By: Claude Sonnet 4.6 --- packages/backend/src/lib/gamification.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/lib/gamification.ts b/packages/backend/src/lib/gamification.ts index a6c3a51..3e6fd82 100644 --- a/packages/backend/src/lib/gamification.ts +++ b/packages/backend/src/lib/gamification.ts @@ -195,7 +195,9 @@ export async function checkAchievements(db: DB, userId: string, category?: strin .update(user_achievements) .set({ progress, - date_unlocked: isUnlocked ? existing[0].date_unlocked || new Date() : null, + date_unlocked: isUnlocked + ? (existing[0].date_unlocked ?? new Date()) + : existing[0].date_unlocked, }) .where( and(