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
- Urgent Help
Hello Appwrite team, I urgently need your help. I am the founder of OnBuch, an EdTech application used by around 10,000 users in Cameroon. In the last two day...
- How to use dart workspaces to deploy a f...
Hello, I'm developing a Flutter application and I would like to leverage dart pub workspaces to deploy a function with a dart runtime as advertised here : http...
- Migration from Cloud to Self-Hosted not ...
Hello Appwrite Community, I've got the problem, that when I try to migrate my Appwrite Project from the cloud to my self-hosted Appwrite, that an API Key is mi...