feat: delete all user likes when user account deleted
This commit is contained in:
+10
-5
@@ -88,13 +88,18 @@ export const deleteUser = internalMutation({
|
|||||||
.withIndex('by_user_id', q => q.eq('userId', userRecord._id))
|
.withIndex('by_user_id', q => q.eq('userId', userRecord._id))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
const userPostDeletePromises = [];
|
const userLikes = await ctx.db
|
||||||
|
.query('likes')
|
||||||
|
.withIndex('by_user_post_id', q => q.eq('userId', userRecord._id))
|
||||||
|
.collect();
|
||||||
|
|
||||||
for (const post of userPosts) {
|
await Promise.all(
|
||||||
userPostDeletePromises.push(ctx.db.delete(post._id));
|
userPosts.map(async post => await ctx.db.delete(post._id))
|
||||||
}
|
);
|
||||||
|
|
||||||
await Promise.all(userPostDeletePromises);
|
await Promise.all(
|
||||||
|
userLikes.map(async like => await ctx.db.delete(like._id))
|
||||||
|
);
|
||||||
|
|
||||||
await ctx.db.delete(userRecord._id);
|
await ctx.db.delete(userRecord._id);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user