From 04b0ec1a71d41606c74419d98c02236a24c888a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Tue, 10 Mar 2026 11:13:01 +0100 Subject: [PATCH] fix: revoke gamification points on recording delete + fix comment collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deleteRecording now queues revokePoints for RECORDING_CREATE (and RECORDING_FEATURED if applicable) before deleting a published recording, so leaderboard points are correctly removed - Fix comment stat/achievement queries using collection "recordings" instead of "videos" — comments are stored under collection "videos", so the count was always 0, breaking COMMENT_CREATE stats and social achievements Co-Authored-By: Claude Sonnet 4.6 --- .../src/graphql/resolvers/recordings.ts | 22 +++++++++++++++++++ packages/backend/src/lib/gamification.ts | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/recordings.ts b/packages/backend/src/graphql/resolvers/recordings.ts index 50a1ac2..1f4eba3 100644 --- a/packages/backend/src/graphql/resolvers/recordings.ts +++ b/packages/backend/src/graphql/resolvers/recordings.ts @@ -251,6 +251,28 @@ builder.mutationField("deleteRecording", (t) => if (!existing[0]) throw new GraphQLError("Recording not found"); if (existing[0].user_id !== ctx.currentUser.id) throw new GraphQLError("Forbidden"); + if (existing[0].status === "published") { + await gamificationQueue.add("revokePoints", { + job: "revokePoints", + userId: ctx.currentUser.id, + action: "RECORDING_CREATE", + recordingId: args.id, + }); + if (existing[0].featured) { + await gamificationQueue.add("revokePoints", { + job: "revokePoints", + userId: ctx.currentUser.id, + action: "RECORDING_FEATURED", + recordingId: args.id, + }); + } + await gamificationQueue.add("checkAchievements", { + job: "checkAchievements", + userId: ctx.currentUser.id, + category: "content", + }); + } + await ctx.db.delete(recordings).where(eq(recordings.id, args.id)); return true; diff --git a/packages/backend/src/lib/gamification.ts b/packages/backend/src/lib/gamification.ts index 3e6fd82..2e754de 100644 --- a/packages/backend/src/lib/gamification.ts +++ b/packages/backend/src/lib/gamification.ts @@ -116,7 +116,7 @@ export async function updateUserStats(db: DB, userId: string): Promise { const commentsResult = await db .select({ count: count() }) .from(comments) - .where(and(eq(comments.user_id, userId), eq(comments.collection, "recordings"))); + .where(and(eq(comments.user_id, userId), eq(comments.collection, "videos"))); const commentsCount = commentsResult[0]?.count || 0; const achievementsResult = await db @@ -279,7 +279,7 @@ async function getAchievementProgress( const result = await db .select({ count: count() }) .from(comments) - .where(and(eq(comments.user_id, userId), eq(comments.collection, "recordings"))); + .where(and(eq(comments.user_id, userId), eq(comments.collection, "videos"))); return result[0]?.count || 0; }