I'm designing a restFUL api with :
- couchDB as database
- nodeJS + expressJS for the server
BackboneJS : rich-client app
I have 3 entities:
- user : Can have multiple teams
- team : Can have multiple users and projects
- project : Can have at most 1 team and multiple users (this users are bonus users that are not in the team but can work on this project)
This is my actual DB pattern, It is close to the SQL joins syntax and I don't know if it's the best way to do this...
User
{
"_id": "233e91578810ee8462b33bd1",
"type": "user",
"email": "[email protected]"
"teams": [b6e9157886462b33bd1f2, a6e9157886462b33bd1f6],
}
Team
{
"_id": "b6e9157886462b33bd1f2",
"type": "team",
"users": ["233e91578810ee8462b33bd1", "b8a6462b33bd1fb0068ab"],
"projects": ["456abe54a65b6a5aa5ea63cd", "a5eba546a6edc313avsb068"],
}
Project
{
"_id": "ba5c60ee8462b33bd1fb00684c",
"type": "project",
"team": "b6e9157886462b33bd1fb0068ab",
"users": ["aae9157886462b33bd1fb0068a", "abac5d6c7d99a6c005c26"]
}
I'm inexperienced with restFUL api, but with this schema I have to update in a bidirectionnal way.
For instance : A user is added in a team, I have to add this userID in the team entity, and I have to add the teamID in the user entity.
I also give you my API routes :
GET api/user/:id -> return user data
PUT api/user/:id -> update user data
GET api/team/:id -> return team data
PUT api/team/:id -> update team data
(I have issue with the last one, because there is differents update possibilities, addUser, removeUser, and when the GET ROUTE is called, I have to know which kind of update it is in order to update in a bidirectional way)