RS School - NodeJS Course - 2021 Q4

Task 10. REST service - NestJS

About

REST service application which used PostgreSQL database with TypeORM library, built on NestJS framework and containerized by Docker

Technical task

How to install and use

  • Using Docker Compose
    1. Install Docker and Docker Compose
    2. Clone this repository
    3. Switch to task_10_nestjs branch
    4. Command string for start PostgreSQL DB in Docker: docker-compose up
    5. Run npm i to install dependencies
    6. Run npm run start:dev to start REST-service app
    7. Command string for tests (start app in docker image first): npm run test:auth
  • Application starts on port 4000 by default
  • After starting the app you can open in your browser OpenAPI documentation by typing http://localhost:4000/doc/

Application operate with the following resources

  • User (with attributes):
    { id, name, login, password }
  • Board (set of columns):
    { id, title, columns }
  • Column (set of tasks):
     { id, title, order }
  • Task:
    {
      id,
      title,
      order,
      description,
      userId, //assignee
      boardId,
      columnId
    }

Details

  1. For User, Board and Task REST endpoints with separate router paths should be created

    • User (/users route)
      • GET /users - get all users (remove password from response)
      • GET /users/:userId - get the user by id (ex. “/users/123”) (remove password from response)
      • POST /users - create user
      • PUT /users/:userId - update user
      • DELETE /users/:userId - delete user
    • Board (/boards route)
      • GET /boards - get all boards
      • GET /boards/:boardId - get the board by id
      • POST /boards - create board
      • PUT /boards/:boardId - update board
      • DELETE /boards/:boardId - delete board
    • Task (boards/:boardId/tasks route)
      • GET boards/:boardId/tasks - get all tasks
      • GET boards/:boardId/tasks/:taskId - get the task by id
      • POST boards/:boardId/tasks - create task
      • PUT boards/:boardId/tasks/:taskId - update task
      • DELETE boards/:boardId/tasks/:taskId - delete task
  2. When somebody DELETEs Board, all its Tasks should be deleted as well.

  3. When somebody DELETEs User, all Tasks where User is assignee should be updated to put userId = null.

Logging

The App implements a Logging service. Logging supports multiple logging levels and store logging level in environment variable.

Three levels of logging are supported:

  • error
  • warn
  • info

To define max logging level set variable LOGGING_LEVEL in the .env file.

  • Events with defined in .env logging level are logging to Console and file ./logs/common.log
  • Events with level error are logging to the file ./logs/error.log too
  • uncaughtException and unhandledRejection events are logging with level error

Developer environment and instruments

  • Node 16.13.0
  • JWT Authorization
  • TypeScript 4.5.2
  • NestJS - server-side node.js framework
  • PostgreSQL DB
  • TypeORM
  • Docker
  • Jest 27.3.1
  • Supertest 6.1.6
  • ESLint 8.3.0
  • TSDoc 0.0.4
  • Npm 8.1.0