Calculates the cashback amount for each purchase from a reseller
- Node.js
- Express with middleware
- MongoDB with Mongoose
- Docker and Docker Compose
- External request with node-fetch
- Cursor-based pagination without external library
- Basic and JWT authentication strategies with Passport
- Application logs with Winston
To check if the prerequisites are installed, just use the following commands:
docker -v
docker-compose -v
make -v
Just run npm test
-
Run
make
from root project -
Create a reseller
curl -X POST \ -d '{ "email": "marcus@gmail.com", "password": "12345678", "cpf": "12345678901", "full_name": "Marcus" }' \ localhost:3001/resellers
-
Authenticate as reseller. This will generate a JWT token as response
curl -X POST --user 12345678901 localhost:3001/resellers/auth
The password will be prompted
-
Create a purchase. Replace
TOKEN
with the token generated in step 3curl -X POST -H "Authorization: Bearer TOKEN" \ -d '{ "code": "546", "data": "2020/04/10", "amount": 100000 }' \ localhost:3001/resellers/12345678901/purchases
-
Get purchases. Replace
TOKEN
with the token generated in step 3curl -X GET -H "Authorization: Bearer TOKEN" localhost:3001/resellers/12345678901/purchases
The query params
next
andprevious
can be used to navigate between pages. Default page size is 5 -
Get cashback amount. Replace
TOKEN
with the token generated in step 3curl -X GET -H "Authorization: Bearer TOKEN" localhost:3001/resellers/12345678901/purchases/cashback