Back

Adding and Deleting Relationships

  • 0
  • React Native
Prajyot
30 Mar, 2025, 15:57

I am currently applying a very ugly way to manage adding and subtracting team members to the team, is there a better way to do this?:

export async function removeMembersFromTeam( teamId: string, memberIds: string[] ): Promise<void> { try { const team = await databases.getDocument( config.databaseId!, config.teamsCollectionId!, teamId );

TypeScript
const updatedMembers = team.members.filter(
  (member: any) => !memberIds.includes(member.$id)
);

await databases.updateDocument(
  config.databaseId!,
  config.teamsCollectionId!,
  teamId,
  { members: updatedMembers }
);
console.log("Members removed successfully.");

} catch (error) { console.error("Error removing members from team:", error); throw error; } }

TL;DR
To manage team members better, developers can use the provided code. It removes team members efficiently by filtering out specified member IDs from the team's list.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more