Here is a project to do some backend stuffs. Let's have some fun! ✨
You will need the following to work on this workshop:
Item | Description | Documentation |
---|---|---|
⚙️ nodejs | Duh! | https://nodejs.org/en/ |
🐳 Docker | we will use docker to launch a postgres instance | https://www.docker.com/get-started |
🧶 yarn | We will use yarn as the package manager for this project | https://yarnpkg.com/getting-started/install |
yarn start:db
yarn test:watch
yarn start:dev
yarn build
Our sample database contains developers along with their squads, their skills and their ownerships on repositories.
Let's take a look at the schema:
Guideline | Description |
---|---|
💪 Use only typescript | No javascript allowed! |
💪 Be modular | nestjs is based on the same principles as angular. Remember modules are cool! |
💪 Follow RESTful principles | Define your endpoints in the most logical way from these principles |
💪 Make sure to validate inputs | Endpoints should return a specific response when input is invalid |
💪 Standardize responses | If a resource is not found, return a 400 response, if something goes wrong, return a 500, etc |
💪 Test your code | Make sure the codebase is properly tested |
This endpoint should return an array of objects containing squads data and an array of developers.
You will have to use prisma to generate a model; you will then be able to use prisma client to interact with the database.
{
result: [
{
id: number,
name: string,
devs: [
{
id: number,
name: string,
role: string
}
]
},
// ...
]
}
This endpoint should return an object containing the dev infos as well as his squad, his skills and his ownerships.
developer id (number)
{
result: {
id: number,
name: string,
squad: {
id: number,
name: string,
},
skills: [
{
id: number,
name: string,
level: number,
aquiredAt: Date
},
// ...
],
ownerships: [ // repos
{
id: number,
name: string
},
// ...
]
}
}
By providing the id of a skill, we expect to get the developers who aquired this skill.
skill id (number)
{
result: [
{
id: number,
name: string,
level: number,
aquiredAt: Date
}
// ...
]
}
This endpoint should change the squad of a developer and return the developer.
developer id (number)
new squad id (number)
{
result: {
id: number,
name: string,
squad: {
id: number,
name: string,
},
}
}
This route is a tricky one. We want to change the owner of a repo by picking, within a squad, the developer having the most experience in a list of skills. If no developer stands out from the crowd, then we shall choose by order of precedence the champion or the squad owner within the squad.
{
idRepo: number,
idSquad: number,
skills: number[]
}
{
result: boolean
}
We want more documentation! Let's setup a swagger on our api to make sure routes can be easily interacted with and understood.
- Inputs should be documented
- Outputs (possible responses) should all be documented
- A description of the route should be present
This feature implies to alter the database and its model in order to store a login and a password for each user.
As for the login route:
{
login: string,
password: string
}
{
result: {
token: string
}
}
Let's secure our api now! All our routes should be restricted to logged users.
All our routes should now require authentication. A proper response should be returned if the caller is unauthorized.