/store-manager

Backend project for managing a store's inventory using Node JS, MySQL, Express JS, MSC architecture and tests with Mocha, Chai and Sinon

Primary LanguageJavaScript

Store Manager

Project

Backend project for managing a store's inventory with a simple CRUD (Create, Read, Update, Delete). In this project it was possible to put into practice lessons learned with the MSC architecture (Model, Service and Controller), Node JS for code execution, Express JS for the creation of the API that communicates with the database, MySQL to store the data in the database, Mocha/Chai for test development and Sinon JS to stub the functions of the MSC layers

Developed using

JavaScript, Node JS, MySQL, Express JS, MSC Architecture, Mocha, Chai, Sinon

API Endpoints

Products
  • Select all products
Method: GET
Endpoint: /products
  • Select products by ID
Method: GET
Endpoint: /products/:id
  • Create product
Method: POST
Endpoint: /products
Body example:
{
  "name": "example"
}
  • Update product
Method: PUT
Endpoint: /products/:id
Body example:
{
  "name": "new_name_example"
}
  • Delete product
Method: DELETE
Endpoint: /products/:id
  • Search product by name
Method: GET
Endpoint: /products/search?q={query}
Sales
  • Select all sales
Method: GET
Endpoint: /sales
  • Select sales by ID
Method: GET
Endpoint: /sales/:id
  • Create sale
Method: POST
Endpoint: /sales
Body example:
[
  {
    "productId": 1,
    "quantity": 1
  },
  {
    "productId": 2,
    "quantity":5
  }
]
  • Update sales
Method: PUT
Endpoint: /sales/:id
Body example:
 [
  {
    "productId": 1,
    "quantity":10
  },
  {
    "productId": 2,
    "quantity":50
  }
]
  • Delete sale
Method: DELETE
Endpoint: /sales/:id

Running the project

1 - Clone the project
2 - Enter the directory store-manager/
3 - Start docker
4 - Run the command docker compose up -d
5 - Run the command docker exec -it store_manager bash
6 - Run the command npm install inside docker to install
7 - Run the command npm run migration inside docker to create database
8 - Run the command npm run seed inside docker to populate database (if you need to repopulate, use this command again)
9 - Run the command npm run debug inside docker to run application

Checking tests

1 - Do the previous steps up to 6
2 - Run the command npm run test:mocha inside docker