How do you remove a user from a team without knowing the MembershipId? The only way I found is to list all Memberships of the team and then loop over all of those to check the userId. This is so much performance overhead for such a simple task. Is there a better way? Edit: I'm speaking of server sdk here.
var teams = new Teams(client);
var allGroupMemberships = await teams.ListMemberships(groupId);
foreach (Membership membership in allGroupMemberships.Memberships)
{
if (membership.UserId != user.Id)
continue;
await teams.DeleteMembership(groupId, membership.Id);
}
What if you use listMemberships from Users?
https://appwrite.io/docs/references/cloud/server-nodejs/users#listMemberships
So you only will have search the teamId in the list of memberships of the user:
var users = new Users(client);
var teams = new Teams(client);
var userMemberships = await users.ListMemberships(userId);
foreach (Membership membership in userMemberships.memberships)
{
if (membership.teamId != teamId)
continue;
await teams.DeleteMembership(groupId, membership.Id);
}
I'm not sure about all code, but it should be something like that
Recommended threads
- Storage System
Hey guys, quick question regarding massive storage scaling. I’m working in digital forensics and I’m constantly dealing with huge binary disk images, usually be...
- _APP_OPTIONS_ROUTER_PROTECTION
Hi Everyone, I just setup a fresh 1.9.0 on a server. Configured everything and now when i try to connect to appwrite for first time setup i get a _APP_OPTIONS_R...
- Selfhost - Starting Docker containers fa...
I am stuck at installing appwrite. Specifically, the containers dont want to start up. The images are downloaded and ready. Dockhand is reporting containers st...