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
- MariaDB refuses to connect to appwrite
Earlier, I tried updating my Appwrite version from 18.1.x to the latest release because my Flutter package required it to function properly. I used the official...
- executeFunction intermittently throws Fo...
Environment: Flutter app using the Appwrite Flutter SDK, calling executeFunction for [describe endpoint, e.g. live-stream-related function]. *Description*: Int...
- Console display all Databases as TablesD...
While looking at an issue with <@1231860789355347971> we saw that the console was displaying ALL databases as `TablesDB` even if the real type in the API is `le...