fix: revoke gamification points on recording delete + fix comment collection
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -251,6 +251,28 @@ builder.mutationField("deleteRecording", (t) =>
|
|||||||
if (!existing[0]) throw new GraphQLError("Recording not found");
|
if (!existing[0]) throw new GraphQLError("Recording not found");
|
||||||
if (existing[0].user_id !== ctx.currentUser.id) throw new GraphQLError("Forbidden");
|
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));
|
await ctx.db.delete(recordings).where(eq(recordings.id, args.id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export async function updateUserStats(db: DB, userId: string): Promise<void> {
|
|||||||
const commentsResult = await db
|
const commentsResult = await db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(comments)
|
.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 commentsCount = commentsResult[0]?.count || 0;
|
||||||
|
|
||||||
const achievementsResult = await db
|
const achievementsResult = await db
|
||||||
@@ -279,7 +279,7 @@ async function getAchievementProgress(
|
|||||||
const result = await db
|
const result = await db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(comments)
|
.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;
|
return result[0]?.count || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user