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.
- Node.js
- Express.js
- Express Rescue
- DotEnv
- Mocha.js
- Chai.js
- Sinon.js
- Docker
- MySQL
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.
git clone git@github.com:jun1orcarvalh0/api-store-manager.git
cd api-store-manager
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.
docker exec -it store_manager bash
Installing the dependencie:
npm install
Running the application:
npm start
npm run test:mocha
- 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.
- 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.
- Create/Update a product:
{
"name": "Nome do Produto"
}
- Create/Update a sale:
[
{
"productId": 1,
"quantity": 10
},
{
"productId": 2,
"quantity": 5
}
]
50 tests were developed that cover 100% of the application: