코파일럿이 코드리뷰때 남겨준 아래의 의견을 바탕으로
수정이 필요함.
When a user is removed from rooms using $pull, rooms might end up with zero participants or orphaned private chats. Additionally, if the deleted user was the admin of a group chat, the admin field becomes invalid. Consider handling these edge cases: 1) Delete rooms that have no participants left, 2) Reassign admin role to another participant if the admin is being deleted, or 3) Add validation to prevent these invalid states.
await Room.updateMany(
{ "participants.userId": toBeDeletedUserId },
{ $pull: { participants: { userId: toBeDeletedUserId } } },
);
코파일럿이 코드리뷰때 남겨준 아래의 의견을 바탕으로
수정이 필요함.
When a user is removed from rooms using $pull, rooms might end up with zero participants or orphaned private chats. Additionally, if the deleted user was the admin of a group chat, the admin field becomes invalid. Consider handling these edge cases: 1) Delete rooms that have no participants left, 2) Reassign admin role to another participant if the admin is being deleted, or 3) Add validation to prevent these invalid states.