Skip to content

juancamiloqhz/nest-challenge

Repository files navigation

Nest.js Api Challenge

Description

This is a simple API that allows you to make CRUD operations on a database. It was made using Nest.js, Prisma ORM, Passport.js (JWT) and PostgreSQL.

Consists of 4 main modules:

  • Auth: Handles the authentication and authorization of the users using Passport.js and JWT.
  • Users: Handles the CRUD operations of the users.
  • Posts: Handles the CRUD operations of the posts.
  • Comments: Handles the CRUD operations of the comments.

With the following routes:

  • Auth: /api/v1/users
    • POST /sign_up
    • POST /sign_in
  • Users: /api/v1/users (protected)
    • GET /
    • GET /me Get the current user info
    • PATCH / Update the current user info
    • PATCH /change_password Change the current user password
    • PATCH /change_role Change the current user role (admin only)
    • DELETE / Delete the current user account
  • Posts: /api/v1/posts (protected)
    • GET / All PUBLISHED posts
    • GET /:id Get a PUBLISHED post
    • POST /
    • PATCH /:id
    • DELETE /:id
  • Comments: /api/v1/comments (protected)
    • GET /:postId Get all comments of a post
    • POST /:postId Create a comment on a post
    • PATCH /:id Update a comment
    • DELETE /:id Delete a comment

With 2 types of E2E tests:

  1. Using Cucumber.js (Gherkin), SuperTest and Chai
  2. Using Jest and Pactum

Installation

$ npm install

Running the app

# start the development database (docker)
$ docker-compose up -d dev-db

# migrate the database and seed it with data
$ npm run prisma:dev:deploy

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test 1

With Cucumber.js (Gherkin), SuperTest and Chai

$ npm run test:e2e:cucumber

Test 2

With Jest and Pactum

$ npm run test:e2e:pactum