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; }