/project-store-manager

API developed using MSC (model-service-controller), which manages dropshipping sales where you can create, view, delete and update products and sales.

Primary LanguageJavaScript

Welcome to the Store Manager Project repository!

Introduction

I developed the API following the MSC (model-service-controller) architecture.

The API is a dropshipping sales management system where you can create, view, delete and update products and sales. MySQL database is used for data management. Unit tests were also developed for all application layers. Also, the API is RESTful.

Express was used to create the routes and manage them, Sinon was used to mocha the functions, both internal and database access. The Chai was used to create the tests.

Installation

Installation instructions

Clone the repository

git clone git@github.com:lucas-da-silva/project-store-manager.git

Enter the repository

cd project-store-manager

Climbing the containers (docker is needed)

docker-compose up -d

Entering the Node.js container

docker exec -it store_manager bash

Install dependencies

npm install

Creating the database and tables

npm run migration

Inserting data into tables

npm run seed

Run the application

npm start

You can use Thunder Client or Insomnia (or whatever) to check the API.

Run the tests

npm test

To stop containers

docker-compose down

Aplication

As the MSC software architecture was used, the database access functions are in the Model layer, the business rules validations are in the Service layer, and the contact with request and return are in the Controller layer.

In the routes directory we have the definition of all routes. And they are the following:

Products routes

  • GET /products: all products are returned;

  • GET /products/:id: only the product with the id present in the URL is returned;

  • GET /products/search: returns products based on q from the database, if it exists;

    The query params of the request should follow the format below:
    http://localhost:PORT/products/search?q=Martelo
    
  • DELETE /products/:id: only the product with the id present in the URL is deleted;

  • PUT /products/:id: only the product with the id present in the URL is updated;

    The request body should follow the format below
    {
      "name": "Martelo do Batman"
    } 
    
  • POST /products: register a new product in the database;

    The request body should follow the format below
    {
      "name": "ProdutoX"
    }
    

Sales routes

  • GET /sales: all sales are returned;

  • GET /sales/:id: only the sale with the id present in the URL is returned;

  • DELETE /products/:id: only the sale with the id present in the URL is deleted;

  • PUT /sales/:id: only the sale with the id present in the URL is updated;

    The request body should follow the format below
    [
      {
        "productId": 1,
        "quantity": 10
      },
      {
        "productId": 2,
        "quantity": 50
      }
    ]
    
  • POST /sales: register a new sale, being possible to register several products through the same request;

    The request body should follow the format below
    {
      "name": "ProdutoX"
    }
    

There are middlewares that were created to validate the data sent in the requests.

And also, unit tests for each of these routes, middlewares and validations in the tests/unit directory.

Technologies used

Node.js Express MySQL Docker

I got the badges from github from Iuri;