Giter VIP home page Giter VIP logo

engagexr's Introduction

EngageXr coding assignment

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

Features covered

  • Used Typescript in the project
  • Implemented Typescript Sequelize
  • Basic JWT Authentication: ability to log in as administrator
  • Used Node, Express, Sequelize, Sequelize-Typescript, JWT, ESlint, Prettier, Winston Logger, express-validator
  • 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 to enforce authorisation
  • 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 MySQL as database choice. Please setup MySQL in the system before installing and running the project.
  • After installing MySQL in the system, create a database inside.
  • Once you setup your mysql database you need to set the database name, username, password in src/configs/sequelizeconfig.ts file
key Type Description
database string Your MYSql database name.
username string Your username
password string Your password.
  • All the API reference is given in the API Reference docs. However, 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 logs folder under the root directory.

Environment Variables

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

SECRET=35c452171f3505f6516011ed1945212

Run Locally

Clone the project

  git clone https://github.com/saurabhk06/engagexr.git

Go to the project directory

  cd engagexr

Install dependencies

  npm install

Run the server locally in development

  npm run dev

Build

  npm run build

Start

Run the server after running the build.

  npm start

Tech Stack

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

API Reference

Auth API

Signup user

  POST http://localhost:4000/api/signup
Body Payload Type Description
firstName string Required.
lastName string Required.
email string Required.
password string Required.
role string OPTIONAL: GUEST/ADMIN. Defaults. GUEST

Signin user

  POST http://localhost:4000/api/signin
Body Payload Type Description
email string Required.
password string Required.

Company API

All the company 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 [YOUR_TOKEN].

Create a new company

  POST http://localhost:4000/api/create-company
Body Payload Type Description
name string Required.
email string Required.
phone string OPTIONAL.
website string OPTIONAL.
Headers Type Description
Content-Type string Required.
Authorization string Required.

Get all companies

  GET http://localhost:4000/api/companies
Headers Type Description
Content-Type string Required.
Authorization string Required.

Get company by company id.

  GET http://localhost:4000/api/company/:companyId
Headers Type Description
Content-Type string Required.
Authorization string Required.

Update company by company id.

  PATCH http://localhost:4000/api/company/:companyId
Body Payload Type Description
name string OPTIONAL.
email string OPTIONAL.
phone string OPTIONAL.
website string OPTIONAL.
Headers Type Description
Content-Type string Required.
Authorization string Required.

Delete company by company id.

  DELETE http://localhost:4000/api/company/:companyId
Headers Type Description
Content-Type string Required.
Authorization string Required.

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 [YOUR_TOKEN].

Create a new employee

  POST http://localhost:4000/api/create-employee
Body Payload Type Description
companyId number Required.
firstName string Required.
lastName string Required.
email string Required.
phone string OPTIONAL.
Headers Type Description
Content-Type string Required.
Authorization string Required.

Get all employees

  GET http://localhost:4000/api/employees
Headers Type Description
Content-Type string Required.
Authorization string Required.

Get employee by employee id.

  GET http://localhost:4000/api/employee/:employeeId
Headers Type Description
Content-Type string Required.
Authorization string Required.

Get employee by company id.

  GET http://localhost:4000/api/company/:companyId/employees
Headers Type Description
Content-Type string Required.
Authorization string Required.

Update employee by employee id.

  PATCH http://localhost:4000/api/employee/:employeeId
Body Payload Type Description
firstName string OPTIONAL.
lastName string OPTIONAL.
email string OPTIONAL.
phone string OPTIONAL.
Headers Type Description
Content-Type string Required.
Authorization string Required.

Delete employee by employee id.

  DELETE http://localhost:4000/api/employee/:employeeId
Headers Type Description
Content-Type string Required.
Authorization string Required.

Author

  • Saurabh Kumar (DamcoGroup)

engagexr's People

Contributors

saurabhk06 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.