Skip to content

Commit

Permalink
Server: Added get balance endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jerichofs committed Jan 7, 2020
1 parent b8e145b commit c752144
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/controllers/balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let data = require("../data");

const getBalance = (req, res) => {
return res.status(200).json({
balance: data.accountValue
});
};

module.exports = {
getBalance
};
17 changes: 17 additions & 0 deletions src/routes/balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const express = require("express");
const balance = express.Router();

const { getBalance } = require("../controllers/balance");

// Fetch current account balance
balance.get("/", getBalance);

// handle 404 error
balance.use((req, res) => {
res.status(404).json({
status: 404,
msg: "Not Found."
});
});

module.exports = balance;
6 changes: 5 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/**
* Note: As i understood i shouldn't be using any types of persistent database such as mysql or postgresql instead in-memory storage so the data is going to be in the form of plain objects
* Note: As i understood i shouldn't be using any types of persistent database
* such as mysql or postgresql, instead in-memory storage is required
* so the data is going to be stored in the form of plain objects
*/
const express = require("express");

const transactions = require("./routes/transactions");
const balance = require("./routes/balance");

const app = express();

const port = 3000;

app.use("/transactions", transactions);
app.use("/balance", balance);

app.use((req, res) => {
return res.status(404).json({
Expand Down

0 comments on commit c752144

Please sign in to comment.