To calculate the bill, you need to consider the tax of the country from which the order came from and the reduction.
Here is the tax table used in the exercise:
Country | Code | Tax |
---|---|---|
Spain | ES | 19% |
France | FR | 20% |
Germany | DE | 20% |
United Kingdom | UK | 21% |
Italy | IT | 25% |
For the order {"prices":[15.99],"quantities":[1],"country":"ES","reduction":"STANDARD"}
, for
example, the response should be {"total":19.03}
.
Following the STANDARD reductions applied for the most part of the orders:
Total | Reduction |
---|---|
>= 50 000 EUR | 15 % |
>= 10 000 EUR | 10 % |
>= 7 000 EUR | 7 % |
>= 5 000 EUR | 5 % |
>= 1 000 EUR | 3 % |
For the order
{"prices":[4.1,8.03,86.83,65.62,44.82],"quantities":[10,3,5,4,5],"country":"FR","reduction":"STANDARD"}
,
for example, the response should be {"total":1147.49}
.
Note that:
- discounts are applied after taxes;
- other types of discounts may appear. Plan the code to be scalable if further discounts are needed.
You should only change the src
folder in this repository. All other folders and files should
remain as they are today.
api
is the folder where the mock came from.dist
is the output generated by your code insrc
once you run the command line to build or develop the project.scripts
is used to create helpers for the repository.- The
src
source folder is where you should create the code to solve this exercise, feel free to organise it as you wish. The mandatory file ismain.js
which is the entry point for your application code.
-
Install project dependencies
npm run install
-
Run server and mock data
npm run dev
- In order to play, you will need to GET the API located at
http://localhost:3000/api/orders
. - By opening the following url
http://localhost:8080/
you will land on the destination page. - We don't need a user interface for this exercise, you can open the console and view the result.