Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jpb06/dev-friends-backend-starter

Let's do some backend things using nestjs and prisma!
https://github.com/jpb06/dev-friends-backend-starter

jest nestjs prisma workshop

Last synced: 1 day ago
JSON representation

Let's do some backend things using nestjs and prisma!

Awesome Lists containing this project

README

        

# ๐Ÿฅ‡ DevFriends backend workshop

[![Open in Visual Studio Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://open.vscode.dev/jpb06/dev-friends-backend-starter)
![Last commit](https://img.shields.io/github/last-commit/jpb06/dev-friends-backend-starter?logo=git)

Here is a project to do some backend stuffs. Let's have some fun! โœจ

ย ย ย ย ย ย ย ย ย ย 

## โšก Requirements

You will need the following to work on this workshop:

| Item | Description | Documentation |
| --------- | -------------------------------------------------------- | --------------------------------------------- |
| โš™๏ธ nodejs | Duh! | |
| ๐Ÿณ Docker | we will use docker to launch a postgres instance | |
| ๐Ÿงถ yarn | We will use yarn as the package manager for this project | |

## โšก How to start

### ๐Ÿ”ถ Firstof, let's start our database using docker

```bash
yarn start:db
```

### ๐Ÿ”ถ Launching our tests

```bash
yarn test:watch
```

### ๐Ÿ”ถ Launching our backend in dev mode (port 3001)

```bash
yarn start:dev
```

### ๐Ÿ”ถ Building our app for production

```bash
yarn build
```

## โšก Data model

Our sample database contains developers along with their squads, their skills and their ownerships on repositories.

Let's take a look at the schema:

![Diagram](./misc/db-diagram.png)

## โšก Give me features to complete now

### ๐Ÿ”ถ Guidelines

| 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 |


### ๐Ÿ”ถ 1) Provide an endpoint to get all squads with their developers

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.

#### โœ… Expected output

```
{
result: [
{
id: number,
name: string,
devs: [
{
id: number,
name: string,
role: string
}
]
},
// ...
]
}

```


### ๐Ÿ”ถ 2) Provide an endpoint to get a developer

This endpoint should return an object containing the dev infos as well as his squad, his skills and his ownerships.

#### โ–ถ๏ธ Input

```
developer id (number)
```

#### โœ… Expected output

```
{
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
},
// ...
]
}
}
```


### ๐Ÿ”ถ 3) Provide an endpoint to get all the developers matching a skill

By providing the id of a skill, we expect to get the developers who aquired this skill.

#### โ–ถ๏ธ Input

```
skill id (number)
```

#### โœ… Expected output

```
{
result: [
{
id: number,
name: string,
level: number,
aquiredAt: Date
}
// ...
]
}
```


### ๐Ÿ”ถ 4) Provide an endpoint to change the squad of a developer

This endpoint should change the squad of a developer and return the developer.

#### โ–ถ๏ธ Input

```
developer id (number)
new squad id (number)
```

#### โœ… Expected output

```
{
result: {
id: number,
name: string,
squad: {
id: number,
name: string,
},
}
}
```


### ๐Ÿ”ถ 5) Provide an endpoint to update the owner of a repo

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.

#### โ–ถ๏ธ Input

```
{
idRepo: number,
idSquad: number,
skills: number[]
}
```

#### โœ… Expected output

```
{
result: boolean
}
```


### ๐Ÿ”ถ 6) Add swagger to the stack and fully document each route

We want more documentation! Let's setup a swagger on our api to make sure routes can be easily interacted with and understood.

#### โœ… Expected result

- Inputs should be documented
- Outputs (possible responses) should all be documented
- A description of the route should be present


### ๐Ÿ”ถ 7) Provide an endpoint to authenticate users

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:

#### โ–ถ๏ธ Input

```
{
login: string,
password: string
}
```

#### โœ… Expected output

```
{
result: {
token: string
}
}
```


### ๐Ÿ”ถ 8) Secure all the routes

Let's secure our api now! All our routes should be restricted to logged users.

#### โœ… Expected result

All our routes should now require authentication. A proper response should be returned if the caller is unauthorized.