The sales-cashback is an api used to help resellers from a company. In this system, it is possible to create new resellers, register orders from them where it has an state of WAITING_APPROVAL and APPROVED and it was created to motivate all resellers with a cashback in their sales. So it will be applied based in few rules a percentagem of a cashback from an order.
This project is also integrated with Circle/ci so it will be applied few rules before a new commit such as run all the tests.
The challenge proposed is to build an api of cashback where the amount is available as credit which can be used in next buyings from a reseller. So The rules for that cashback is is related to when a reseller buy something it gets a cashback from a certain amount.
The system must has:
-
Route to create a new reseller containing at least email, password, cpf and fullname.
-
Route to save orders requiring product code, amount, date and reseller cpf.
-
All orders must be saved as "waiting approval" whithin on exception, if the cpf is 153.509.460-56 and in that case it will be saved as approved.
-
List all orders saved returning a code, amount, date, % of cashback for that order and status.
-
Get a moment total of cashback which it must be consumed from an external endpoint.
-
Orders with a max total amount of 1k, the reseller it will get 10% of cashback.
-
Orders between 1k and 1.5k, must be applied 15% of cashback.
-
More than 1.5k it must be applied 20% of cashback
All this cases are related to a total amount from a period of time.
npm install
npm start
make production
You need to have a docker and docker-compose installed in your machine.
docker-compose up
The database used is PostgreSQL and it was used an ORM called sequelize.js to integrate Node.js with PostgreSQL.
The database initialization it will pretty much create the database, run the migrations and run all seeds:
npm run build-database
All the endpoints has a documentation by swagger which can also be used as an test interface.
OBS: Swagger ui is only available using docker for this application.
- You must run the application together with swagger.
To Use Swagger-ui you has to follow the stepps bellow:
It has the commands at a Makefile which runs a container with the Swagger-Ui image at localhost:8085.
make swaggerui
The swagger.json is used as a documentation file which it is splited at docs folder. To create this file just run:
npm run swagger-json
If everything goes fine you can access localhost:8085
You can run the applications tests with
npm test
Simple Object Handler is MIT licensed.