1.0.0 • Published 1 year ago

backend_repo v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

EngageXr coding assignment

This project contains the backend code for the EngageXr coding assigment.

Features covered

  • Used Typescript in the project
  • Implemented Sequelize
  • ROle based access JWT authentication for admin, company and user
  • Used Node, Express, Sequelize, JWT, ESlint, Winston Logger, express-validator, module aliasing, postrgres
  • Created Express routing to demonstrate CRUD functionality (Create / Read / Update / Delete) for two API items: Companies and Employees
  • Used Express validation middleware to demonstrate basic payload validation
  • Used Express middleware for authorising to enforce authorisation,company or user,
  • Companies DB table consists of these fields: Name (required), email, phone, website
  • Employees DB table consists of these fields: First name (required), last name (required), Company (foreign key to Companies), email, phone
  • User DB table (Additional table to enforce log in as admin functionality)

Important Instructions

  • This project is built with postgres as database choice. Please setup postgres in the system before installing and running the project.
  • After installing postgres in the system, create a database inside names ad metaseq.
  • Once you setup your postgres database you need to set the database name, username, password in src/configs/sequelizeconfig.ts file
keyTypeDescription
databasestringYour postgres database name.
usernamestringYour username
passwordstringYour password.
  • All api reference is given in bellow and to ease API testing there is a POSTMAN api JSON file added in the root of the project (/postman/engagexr-apis.postman_collection.json) directory. Import this file in the POSTMAN application and test the API with pre-loaded data. More info about API's is given in the API Reference section.

  • you can find the server logs under consoleLogs folder under the src directory.

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

SECRET="shah@123"

Run Locally

Clone the project

  git clone -b main https://github.com/shahahmedp/engageXR-.git

Go to the project directory

  cd engageXRBackedn

Install dependencies

  yarn install

Run the server locally in development

  yarn run dev

Build

  yarn run build

Start

Run the server after running the build.

  yarn start

Tech Stack

Server: Node, Express, Sequelize, JWT, Eslint, prettier, Winston

API Reference

Auth API

Signup user

  POST http://localhost:3000/api/auth/signup
Body PayloadTypeDescription
usernamestringRequired.
emailstringRequired.
passwordstringRequired.
rolearray of stringsOPTIONAL: Admin/Company/user. Defaults. GUEST

Signin user

  POST http://localhost:3000/api/auth/signin
Body PayloadTypeDescription
usernamestringRequired.
passwordstringRequired.

Company API

All the company API requires Authorisation header containing Bearer Token(x-access-token)

  • use the Signin API shown above to generate the token. | Headers | Type | value | | :-------- | :------- | :------------------------- | | Content-Type | string | application/json. | | Authorization | string | Bearer x-access-token. |

Create a new company

  POST http://localhost:3000/api/post/cmpy
Body PayloadTypeDescription
namestringRequired.
emailstringRequired.
phonestringOPTIONAL.
websitestringOPTIONAL.
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Get all companies

  GET http://localhost:3000/api/get/cmpy
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Get company by company id.

  GET http://localhost:3000/api/getbyid/cmpy/:name
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Update company by company id.

  PUT http://localhost:3000/api/putbyid/cmpy/:companyId
Body PayloadTypeDescription
namestringOPTIONAL.
emailstringOPTIONAL.
phonestringOPTIONAL.
websitestringOPTIONAL.
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Delete company by company id.

  DELETE http://localhost:3000/api/deleteById/cmpy:companyId
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Employee API

All the employee API requires Authorisation header containing Bearer Token and Content-Type header

  • use the Signin API shown above to generate the token. | Headers | Type | value | | :-------- | :------- | :------------------------- | | Content-Type | string | application/json. | | Authorization | string | Bearer x-access-token. |

Create a new employee

  POST http://localhost:3000/api/post/emp
Body PayloadTypeDescription
cmpIDstringRequired.
firstNamestringRequired.
lastNamestringRequired.
emailstringRequired.
phonestringOPTIONAL.
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Get all employees

  GET http://localhost:3000/api/get/emp
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Get employee by employee id.

  GET http://localhost:3000/api/getbyid/emp/:employeeId
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Get employee by company id.

  GET http://localhost:3000/api/company/:companyId/employees
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Update employee by employee id.

  put http://localhost:3000/api/putbyid/emp/:employeeId
Body PayloadTypeDescription
firstNamestringOPTIONAL.
lastNamestringOPTIONAL.
emailstringOPTIONAL.
phonestringOPTIONAL.
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Delete employee by employee id.

  DELETE http://localhost:3000/api/deleteById/emp/:employeeId
HeadersTypeDescription
Content-TypestringRequired.
AuthorizationstringRequired.

Author

  • XXXXXXXX ()