Skip to content

Backend application for the inventor website which houses all the feature ranging from blog, access management, ..... membership platform

Notifications You must be signed in to change notification settings

InventorsDev/inventor-backend

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version

Package License

NPM Downloads

CircleCI

Coverage

Discord

Backers on Open Collective

Sponsors on Open Collective

Support us

Description

Nest framework TypeScript starter repository.

Setup the app

Setting up the project on your window/mac system involves various steps that will be discussed in the section

Clone The Project Repository

  1. Click on this link to clone the projects from the GitHub repo (https://github.com/InventorsDev/inventor-backend)

Once you have cloned the project on your system, you will have your copy of the project on your system.

  1. Open the project on your code editor.

Setup Your Environment Variables

For the application to function properly when running it, you need to setup some necessary Environment Variables in your .env file

  1. Create a file .env in your project root folder.
  2. Copy the Environment Variables from your .env.sample to your newly created .env file
NODE_ENV=development

PORT=3888

APP_DATABASE_URL=mongodb://localhost:27017/inventor_app?retryWrites=true&w=majority

LOG_DATABASE_URL=mongodb://localhost:27017/inventor_log?retryWrites=true&w=majority

JWT_SECRET=

JWT_EXPIRES=1h

RATE_LIMIT_REQUEST_SIZE=60

RATE_LIMIT_TTL=30
  1. Create a Cloudinary account with this link
  2. Navigate to your dashboard in your Cloudinary account and copy the following Environment Variables.
//Cloudinary Environment Variables

CLOUDINARY_NAME=[Enter your Cloudinary name here]

CLOUDINARY_KEY=[Enter your Cloudinary key here]

CLOUDINARY_SECRET= [Enter your Cloudinary secret here]

Once you have copied your unique Environment Variables, paste them into your .env file as shown in the code above.

Installation

$  npm  install

Running the app

# development

$  nest  start  --watch

# production mode

$  npm  run  start:prod

Once the application is running, your terminal should display a message similar to:

Inventor application is running on: http://[::1]:3888

Here, 3888 is the port number on which the application is running. This port number depends on the value you specify in your .env file under the PORT variable:

PORT=[YOUR_PORT_NUMBER]

To access the Swagger documentation for the API endpoints, open your web browser and navigate to the following URL, replacing 3888 with your specified port number:

http://[::1]:[YOUR_PORT_NUMBER]/docs/api

This URL will take you to the Swagger interface, where you can explore and interact with the API endpoints.

Using the Provided Endpoints in Swagger Documentation

This guide will walk developers through the process of using the provided endpoints in the Swagger documentation. Follow the steps below to ensure you can successfully interact with the APIs.

Prerequisites

  • Ensure that your development environment is set up and that you have access to the Swagger documentation for the API.

Steps to Use the Provided Endpoints

1. Register a New User

The first step is to register a new user. This is required to create an account that can be used for authentication.

Endpoint: POST /api/v1/auth/register

Request Body:

```json
{
"email": "string",
"password": "string",
"firstName": "string",
"lastName": "string",
"joinMethod": "SIGN_UP",
"location": {
  "type": "Point",
  "coordinates": [
    "longitude",
    "latitude"
  ]
},
"deviceId": "string",
"deviceToken": "string"
}

2. Verify the User

To verify the user using the Swagger documentation, you'll need to provide the userId (the _id given to you in the response after registering) and the token (the emailVerificationCode given to you in the response after registering). These inputs are fields in the Swagger interface.

Endpoint: POST /api/v1/auth/{userId}/verify/{token}/email

Request Body:


3. Log In

Once the user is verified, you can log in to obtain an authentication token.

Endpoint: POST /api/v1/auth/login

Request Body:

{
  "email": "string",
  "password": "string"
}

Response: The response will contain an authentication token, which you will use for authenticated requests.

{
"access_token": "your_auth_token",
"_id": "your_userId",
"email": "your_email_address",
"firstName": "your_firstname",
"lastName": "your_lastname",
"role": [ "USER" ]
}

4. Add the Auth Token to Swagger

To interact with the secured endpoints in the Swagger documentation, you need to add the obtained authentication token.

  1. Open the Swagger documentation for your API.
  2. Click on the Authorize button (usually a padlock icon) at the top of the page.
  3. In the popup that appears, enter your authentication token in the appropriate field. The format usually is:
Bearer your_auth_token
  1. Click Authorize to apply the token.

With the authentication token added, you can now interact with the secured endpoints in the Swagger documentation. The token will be included in the Authorization header of your requests.

Ensure you replace placeholder values (e.g., your_firstname,your_lastname, your_password, your_email_address, your_userId,your_verification_code, your_auth_token) with actual data as per your API setup.

Test

# unit tests

$  npm  run  test



# e2e tests

$  npm  run  test:e2e



# test coverage

$  npm  run  test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

Backend application for the inventor website which houses all the feature ranging from blog, access management, ..... membership platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages