Skip to content

This is a CRUD API for a store manager. It is built using NodeJS, Express and MySQL. I have used the MSC (Models, Services, Controllers) architecture for this project and Docker for containerization. Development was done using TDD(Test Driven Development) and the tests were written using Mocha, chai and sinon.

Notifications You must be signed in to change notification settings

marianarufo/api-store-manager

 
 

Repository files navigation

🏬 Store Manager API

Leia em português!

📃 About

This is a CRUD API for a store manager. It is built using NodeJS, Express and MySQL. I have used the MSC (Models, Services, Controllers) architecture for this project and Docker for containerization. Development was done using TDD (Test Driven Development) and the tests were written using Mocha, Chai and Sinon.

You can Create, Read, Update and Delete (CRUD) products and sales records.

👨‍💻 Technologies

  • Node.js
  • Express.js
  • Express Rescue
  • DotEnv
  • Mocha.js
  • Chai.js
  • Sinon.js
  • Docker
  • MySQL

🛠️ How to run the project

To run this application you need to have Git, Docker and Docker Compose installed on your computer. Docker Compose needs to be at version 2.10.2 or higher.

1 - Clone the repository

git clone git@github.com:jun1orcarvalh0/api-store-manager.git

2 - Enter the project folder

cd api-store-manager

3 - Run the containers by running the command below in the root folder of the application

docker-compose up -d --build

This will start the MySQL container and the NodeJS container. The MySQL container will be running on port 3306 and the NodeJS container will be running on port 3000.

4 - After the containers are running, you will need to connect to the bash of the NodeJS container:

docker exec -it store_manager bash

5 - In the container terminal, install the dependencies and run the application

Installing the dependencie:

npm install

Running the application:

npm start

6 - Run the following command in the container terminal to check test coverage

npm run test:mocha

📚 Documentation

Routes - Products

  • GET /products : Lists all products in the store.
  • GET /products/:IdDoProduto : Lists the product with the desired ID.
  • GET /products/search?q=TERMO_DE_BUSCA : Lists the products with the name entered as a search term.
  • POST /products : Creates a new product, according to the passed body. It must be the "name" property and the name of the product.
  • PUT /products/:IdDoProduto : Changes the name of an existing product with the specified ID. It must be the "name" property and the name of the product.
  • DELETE /products/:IdDeProduto : Deletes the product with the desired ID.

Routes - Sales

  • GET /sales : Lists all sales in the store.
  • GET /sales/:IdDaVenda : Lists the sale with the desired ID.
  • POST /sales : Creates a new sale, according to the body passed. An array of objects must be passed, each with "productId" and "quantity" properties
  • PUT /sales/:IdDaVenda : Changes an existing sale with the specified ID. An array of objects must be passed, each with "productId" and "quantity" properties.
  • DELETE /sales/:IdDaVenda : Deletes a sale with the desired ID.

Body Examples

  • Create/Update a product:
{ 
  "name": "Nome do Produto"
}
  • Create/Update a sale:
[
  { 
    "productId": 1,
    "quantity": 10
  },
  { 
    "productId": 2,
    "quantity": 5
  }
]

🧪 Tests Coverage

50 tests were developed that cover 100% of the application:

Test Coverage - Cobertura dos testes

About

This is a CRUD API for a store manager. It is built using NodeJS, Express and MySQL. I have used the MSC (Models, Services, Controllers) architecture for this project and Docker for containerization. Development was done using TDD(Test Driven Development) and the tests were written using Mocha, chai and sinon.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.7%
  • Shell 2.3%