-
Create a new .env file en each folder: server and client.
-
Copy the content in .env.example file into .env file in their corresponding folder.
-
You need to previously create a Postgres database called store.
-
Make sure the database config credentials match with your postgresql local instance credentials.
- Go to directory server
$ cd service
- Install all necessary dependencies by running the command:
$ npm install
- Run the next command no set the intial data and tables:
$ npm run init-db
- Start the server application:
# If you are running in dev environment
$ npm run dev
# If you are running in prod environment
$ npm run start
Application will start running on http://localhost:5000
- Go to directory client:
$ cd client
- Install all necessary dependencies by running the command:
$ npm install
- Start the client application:
# If you are running in dev environment
$ npm run dev
# If you are running in prod environment
$ npm run start
Application will start running on http://localhost:3000
Once both apps are running, you can start accessing to each endpoint.
To fully test services, you need to follow an specific order.
Both apps (Server and Client) use the same endpoints
- POST /baskets
- Inserts a new basket basket on database, you will receive the recently generated basketId.
- POST /baskets/:basketId/products
- Inserts a new product for the specified basketId param
- You need to send a json object in the body of the request
# To get the correct Product code, you'll need to search int Products table
# Example:
{
"code": "TSHIRT",
"quantity": 4
}
- GET /baskets/:basketId
- Gets the details and totals of the indicated basket
- It returns a JSON object
# If product charge has a promo, 'hasPromo' field will be true
{
"success": true,
"data": {
"total": 125,
"details": [
{
"code": "PEN",
"name": "Pen",
"quantity": 1,
"unitPrice": 5,
"hasPromo": true,
"total": 5
},
{
"code": "TSHIRT",
"name": "T-Shirt",
"quantity": 8,
"unitPrice": 20,
"hasPromo": true,
"total": 120
}
]
}
}
- DELETE /baskets/:basketId
- Exeicutes a soft delete for the indicated basket according to basketId param
Test are currently executing only on server app
- Run the command
$ npm run test
Cases indicated on NodeJSExercise.md are included in file server/test/basket.spec.js
Currently both instances start and run correctly.
Server can execute all endpoint operations.
Client still cant communicate with server container
In case on error, both apps save the messages in log/error.log file. It uses winston logger.
- Promos are saved in Promotions table.
- Each promo has a relationship with a product. A product can have one o more acummulated promos.
- In case you want to stop a promo, just delete it from table.
- Each promo a start and end date. This is to define the validity for them.
- Each promo has a field called calcFuntion which is the name of a function in nodejs. This allows to call promo calculations dynamically.