Follow the steps below to run the application locally on your machine.
- Node.js installed on your machine.
- npm (usually installed with Node.js).
- Git to clone the repository (optional).
- Download and extract the ZIP from the repository or Clone this repository:
git clone https://github.com/hart42/Take-home-assignment
- Install the dependencies:
npm install
- Run the application with the following command:
npm run dev
Reset all data.
-
Request
No route or query parameters. -
Response
HTTP Status 200.
// HTTP Status 200 OK
// No route or query parameters
Returns the account's balance.
-
Request
Use the query parameteraccount_id
.
There should be no content in the body of the requisition -
Response
In the success case, it should return HTTP Status 200 and the value of the account balance. balance is an integer representing the value in cents In case of failure, it should return HTTP Status 404 and the value 0.
// GET /balance?account_id=1234
// No content in the body of the requisition
// Get balance for existing account | HTTP Status 200
{
10
}
// Get balance for non-existing account | HTTP Status 404
{
0
}
Create account with initial balance.
-
Request
The body must have an object with the following properties (respecting these names):- "type": "deposit", (string)
- "destination": "100", (string)
- "amount": 10 (number)
- amount is an integer representing the value in cents
-
Response
If successful, returns HTTP Status 201 and a json in the body in the format:{"destination": {"id":"100","balance":20}}
// HTTP Status 201
{"destination": {"id":"100","balance":20}}
Deposits a new amount into an existing account.
-
Request
The body must have an object with the following properties (respecting these names):- "type": "deposit", (string)
- "destination": "100", (string)
- "amount": 10 (number)
- destination must be the value of a valid account_id;
- amount is an integer representing the value in cents
-
Response
- If successful, returns HTTP Status 201 and a json in the body in the format:{"destination": {"id":"100","balance":20}}
- returns the account with the new value already added
// HTTP Status 201
{"destination": {"id":"100","balance":20}}
Withdrawal of amount from existing account.
-
Request
The body must have an object with the following properties (respecting these names):- "type": "withdraw", (string)
- "origin": "100", (string)
- "amount": 10 (number)
- origin must be the value of a valid account_id;
- amount is an integer representing the value in cents
-
Response
- If successful, returns HTTP Status 201 and a json in the body in the format:{"destination": {"id":"100","balance":20}}
- returns the account with the new value already added
- In case of failure, it should return HTTP Status 404 and the value 0.
// HTTP Status 201
{"origin": {"id":"100","balance":10}}
// Withdraw from a non-existing account | HTTP Status 404
{
0
}
Transfer the value between the source account and the target account.
-
Request
The body must have an object with the following properties (respecting these names):-
"type": "transfer", (string)
-
"origin": "100", (string)
-
"amount": 10 (number)
-
"destination": "42" (string)
-
origin must be the value of a valid account_id;
-
amount is an integer representing the value in cents
-
If the destination account does not exist, a new account will be created with the amount transferred from the source account
-
-
Response
-
If successful, returns the origin account and the destination account with their respective updated balances in a response HTTP Status 201 and a json in the body in the format: {"origin": {"id":"100", "balance":0}, "destination": {"id":"300", "balance":15}}
-
returns the account with the new value already added
-
In case of failure, it should return HTTP Status 404 and the value 0.
-
// HTTP Status 201
{
"origin": {"id":"100", "balance":0},
"destination": {"id":"300", "balance":15}
}
// Transfer from non-existing account | HTTP Status 404
{
0
}