forked from keepsafe-cloud/keepsafe-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (28 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require('express');
const rentCalculations = require('./lib/rentCalculations');
const app = express();
const PORT = process.env.PORT || 3001;
const FixedInterest = process.env.INTEREST || 1.82;
app.get('/', (req, res) => {
res.json({ success: true, message: 'service up and running' });
});
app.get('/health', (req, res) => {
res.json({ success: true, message: 'all services healthy' });
});
// http://localhost:3001/monthlyPayment?amount=20000&years=20
app.get('/monthlyPayment', (req, res) => {
const amount = req.query.amount || 20000;
const length = (req.query.years || 20) * 12;
const monthlyPayment = rentCalculations.calculateMonthlyPayment(amount, length, FixedInterest);
res.json({ success: true, monthlyPayment });
});
// http://localhost:3001/totalRent?amount=20000&years=20
app.get('/totalRent', (req, res) => {
const amount = req.query.amount || 20000;
const length = (req.query.years || 20) * 12;
const totalRent = rentCalculations.calculateTotalRent(amount, length, FixedInterest);
res.json({ success: true, totalRent });
});
app.listen(PORT, () => {
console.debug('Node Js Server is Running');
});