Back

What is the best way to implement teams for groups of users

  • 0
  • Databases
  • Teams
hortigado
19 Apr, 2023, 15:11

Hi, I'm trying to implement teams. But I still haven't decided which is the best way to do it. For example: I want every teacher to create a classroom. And to that class add students. And then return the list of classrooms to the users and teachers. But what would be the best way to join the classroom with teams. 1. Save the $id of the team in the classroom model In this way, I would have to create a relationship (many to many ) Users-Classroom and I think that it would not be optimal since when obtaining the details of a user it would obtain the details of the classrooms. Maybe I could create a list of $ids of the teams to avoid getting data I don't want; But this would also be more complex because you would have to create more functions to edit this list. 2. Save the $id of the classroom in the team preferences In this way, it would have to obtain all the teams to which the user has access. But this would cause me problems if I later want to create a team for something else, such as user groups. It could perhaps be solved by creating a team preference. 3.Create the team with the $id=$id of the classroom I'm sorry but I'm a bit confused. If someone can guide me with the optimal way, I would appreciate it. Greetings

TL;DR
The user is looking for the best way to implement teams for groups of users in a classroom setting. They are considering different approaches, such as saving the team ID in the classroom model or saving the classroom ID in the team preferences. The user is unsure which approach is the most optimal and is looking for guidance. Possible solution: One possible solution could be to save the classroom ID in the team preferences. This way, the user can easily access all the teams they have access to. To avoid potential issues in the future, such as creating teams for other purposes, the user can consider creating a separate team preference for user groups.
Binyamin
19 Apr, 2023, 15:13

Hey,

First of all for the teams aspect are you planning to use Appwrite https://appwrite.io/docs/client/teams ?

hortigado
19 Apr, 2023, 15:15

Yes

Binyamin
19 Apr, 2023, 15:15

Cool Let me go over it couple of minutes

Binyamin
19 Apr, 2023, 15:17

So you have user And each of one of them can be either teacher or a student. no one can be both? Then you have Classes that each teacher can be a teacher within it and and student can learn?

That's means that any user should have a many-to-many relation ships with the classes

Did I got the idea correct?

hortigado
19 Apr, 2023, 15:19

Correct in everything, and yes only the teacher or the one who creates the classroom would have a role like admin

Binyamin
19 Apr, 2023, 15:19

Okay

Binyamin
19 Apr, 2023, 15:20

So this is the way I would go with it

Binyamin
19 Apr, 2023, 15:45

I'll create Team for each class. Then each team will have three roles

  1. Owner
  2. Teacher
  3. Student

Then each teacher is added to a team and then assigned to class as Owner + Teacher. Each student is also added to a team and then assigned as Student.

So for example if we have 3 Teams

  1. Math
  2. Science
  3. Cooking

To get all the teacher in Math we can write (JavaScript but you can easily adapt to any other Appwrite client side SDKs)

TypeScript
  const teamMembers = await teams.listMemberships('MathClassID',[
    Query.search('role','teacher'),
  ])

and we want to get all the students in Math we can write

TypeScript
  const teamMembers = await teams.listMemberships('MathClassID',[
    Query.search('role','student'),
  ])

To get all users memberships and roles we can use the Server SDK as such

TypeScript
const memberships = await users.listMemberships('StudentID');

In case this student is in all classes we get something like this: Notice I've removed a lot of information from the object to make it easy to read

TypeScript
{
  "total"      : 3,
  "memberships": [
    {
      "teamName": "Math",
      "roles"   : ["student"]
    },
    {
      "teamName": "Science",
      "roles"   : ["student"]
    },
    {
      "teamName": "Cooking",
      "roles"   : ["student"]
    }
  ]
}

The only downside in the last step is that it can be used only in Server side SDK. But for that you can easily create a function.

Hope it makes sense

hortigado
19 Apr, 2023, 16:12

Great job friend, the structure seems good to me, but I still have a question where I would store the ClassID. Since, for example, each teacher creates his group-classroom of mathematics. There would come the doubt that i mentioned.

Binyamin
19 Apr, 2023, 16:15

Ohh I got you Missed that part You can create more roles So Let's say teach A Teaches Students 1,2 and 3 Math Then teach A will be in the TeamMath with the roles ['teacher','owner','teacherid'] And each student will have the roles ['student','teacherid']; By using the teacherid as role you can make sure that you'll create a unique lists of

  • Teacher
  • Topic
  • Students For each class
hortigado
19 Apr, 2023, 16:25

Interesting, I hadn't thought of that way. I will implement it if it works for me. Thank you so much

Binyamin
19 Apr, 2023, 16:31

Cool 👍

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