Skip to content

rizki-nm/nestjs-mongodb

Repository files navigation

backend-api

NestJS MongoDB Jest Swagger

Description:

backend-api with CRUD operations to make a request. In order to retrieve/get/create/update/delete JWT is required. (Authorization: Bearer {token} attached to the headers). API provides endpoints for registration and token retrieval (access token). With this access token, the user can access data related to the database through the API because the user is authenticated.

Used Frameworks, libraries, tools, databases:

  • NestJS + MongoDB + Mongoose + Jest

Tools:

  • WebStorm, Swagger

Api Documentation:

Register User

Description

Register new user.

Request

  • Method: POST
  • URL: /auth/register
  • Body:
{
  "username": "string",
  "email": "string",
  "password": "string"
}

Response

  • Status Code: 201 Created
  • Response Format: JSON
Successful Response
{
  "token": "string"
}
Login

Description

Login user.

Request

  • Method: POST
  • URL: /auth/login
  • Body:
{
  "email": "string",
  "password": "string"
}

Response

  • Status Code: 200 OK
  • Response Format: JSON
Successful Response
{
  "token": "string"
}
Get User Profle

Description

Get user profile.

Request

  • Method: GET
  • URL: /auth/profile
  • Headers:
    • Authorization: Bearer {token}

Response

  • Status Code: 200 OK
  • Response Format: JSON
Successful Response
{
  "message": "string",
  "code": "string",
  "data": [
    {
      "name": "string",
      "gender": "string",
      "birthday": "string",
      "horoscope": "string",
      "zodiac": "string",
      "height": "string",
      "weight": "string",
      "interest": ["string"]
    }
  ]
}
Create User Profle

Description

Create user profile.

Request

  • Method: POST
  • URL: /auth/profile
  • Headers:
    • Authorization: Bearer {token}
  • Body:
{
  "name": "string",
  "gender": "string",
  "birthday": "string",
  "height": "string",
  "weight": "string",
  "interest": ["string"]
}

Response

  • Status Code: 201 Created
  • Response Format: JSON
Successful Response
{
  "message": "string",
  "code": "string",
  "data": [
    {
      "name": "string",
      "gender": "string",
      "birthday": "string",
      "horoscope": "string",
      "zodiac": "string",
      "height": "string",
      "weight": "string",
      "interest": ["string"]
    }
  ]
}
Update User Profle

Description

Update user profile.

Request

  • Method: PUT
  • URL: /auth/profile
  • Headers:
    • Authorization: Bearer {token}
  • Body:
{
  "name": "string",
  "gender": "string",
  "birthday": "string",
  "height": "string",
  "weight": "string",
  "interest": ["string"]
}

Response

  • Status Code: 200 OK
  • Response Format: JSON
Successful Response
{
  "message": "string",
  "code": "string",
  "data": [
    {
      "name": "string",
      "gender": "string",
      "birthday": "string",
      "horoscope": "string",
      "zodiac": "string",
      "height": "string",
      "weight": "string",
      "interest": ["string"]
    }
  ]
}

Database schema:

Database Diagram

Software Architecture:

App Diagram

Testing:

Unit test and end to end test using Jest. Go to e2e test.

auth tests:
  • Register a new user
  • Login user
  • Not accept invalid email
  • Not register duplicate email
  • Not login (not register yet)
profile tests:
  • Create new profile
  • Get data profile
  • Update data profile
  • Unauthorized in create profile
  • Unauthorized in update profile
  • Unauthorized in get profile
  • Not accept invalid birthday

Clone and Local Development

git clone git@github.com:rizki-nm/nestjs-mongodb.git
$ pnpm install

Running the app

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

Test

# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors