feat: delete all users posts when user is deleted

This commit is contained in:
Stevan Freeborn
2023-09-10 20:19:31 -05:00
parent 90f95e50a5
commit 1ad65d8b30
12 changed files with 1452 additions and 107 deletions
+13
View File
@@ -44,6 +44,19 @@ export const deleteUser = internalMutation({
return;
}
const userPosts = await ctx.db
.query('posts')
.withIndex('by_user_id', q => q.eq('userId', userRecord._id))
.collect();
const userPostDeletePromises = [];
for (const post of userPosts) {
userPostDeletePromises.push(ctx.db.delete(post._id));
}
await Promise.all(userPostDeletePromises);
await ctx.db.delete(userRecord._id);
},
});