Skip to content

This NestJS application provides user registration service, allowing users to create accounts and store their personal information in a MongoDB database.

Notifications You must be signed in to change notification settings

levyaraujo/nest-authentication

Repository files navigation

User CRUD API made with NestJS and MongoDB

This NestJS application provides user registration service, allowing users to create accounts and store their personal information in a MongoDB database. After registration, a RabbitMQ message is sent to an email microservice, which sends a verification email to the user's email address.

Prerequisites

Before you can use this API, you'll need to have the following software installed:

  • Node.js (version 18.12.1 or higher)
  • npm (version 8.19.2 or higher)
  • Docker (version 20.10.8 or higher)
  • RabbitMQ (version 3.9.7 or higher)
  • MongoDB (version 5.0.15 or higher)

Getting Started 🚀

To get started with the API, follow these steps:

Docker 🐳

  1. Clone this repository or download the zip file;
  2. Unzip the file;
  3. Install the dependencies by running yarn install or npm install;
  4. Open a terminal window and navigate to the project directory;
  5. Run docker compose up to start the server and all the required services (RabbitMQ, MongoDB and Email microservice).

Run the tests 🧪

Unit tests for this API can be run by executing the command yarn test or npm run test. These tests are performed using Jest and cover the API's basic functionality.

Test the API directly in Postman 👨‍🚀:

In order to test in localhost, you need to download the Postman Desktop

Run in Postman

API Endpoints 📡

The following endpoints are available in the API:

API Endpoints 📡 The following endpoints are available in the API:

  • POST /api/users: create a new user account. The request body should contain the user's first_name, last_name, email and avatar file.
  • GET /api/user/{userId}: get a user by ID.
  • GET /api/user/{userId}/avatar: get a user's avatar image.
  • DELETE /api/user/{userId}/avatar: delete a user's avatar image.

Create a new user account

  • URL: POST /api/users
  • Description: Creates a new user account with the given details.
  • Request Body:
    Key Value
    firstName Spider
    lastName Man
    email [email protected]
    avatar Image File
  • Response Body:
    {
      "firstName": "Spider",
      "lastName": "Man",
      "email": "[email protected]",
      "id": "98",
      "createdAt": "2023-04-23T23:25:59.728Z"
    }

Get a user by ID

  • URL: GET /api/user/{ObjectId}
  • Description: Gets the user with the specified ID.
  • Response Body:
{
  "data": {
    "id": 1,
    "email": "[email protected]",
    "first_name": "George",
    "last_name": "Bluth",
    "avatar": "https://reqres.in/img/faces/1-image.jpg"
  },
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}

Get a user avatar image

  • URL: GET /api/user/{ObjectId}/avatar
  • Description: Get the user avatar with specified ObjectId
  • Response: User avatar image

Delete a user avatar

  • URL: DELETE /api/user/{ObjectId}/avatar
  • Description: Delete the user avatar with specified ObjectId
  • Response Body:
{
  "message": "User avatar deleted successfully",
  "status": 200
}

About

This NestJS application provides user registration service, allowing users to create accounts and store their personal information in a MongoDB database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published