Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ module.exports = {
"sourceType": "module"
},
"rules": {
"linebreak-style": 0,
"comma-dangle": 0,
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"no-unused-vars": 0,
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"globals": {
"window": true,
"document": true
},
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"no-unused-vars": 0,
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"globals": {
"window": true,
"document": true
},
}
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.nyc_output
.vscode
.vscode
.nyc_output
2 changes: 1 addition & 1 deletion .nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"processes":{"1c4c8f88-0f58-4e63-aba1-3a6c0b920758":{"parent":"e063fa28-d588-479e-a1b2-4fdbf0782595","children":[]},"e063fa28-d588-479e-a1b2-4fdbf0782595":{"parent":null,"children":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"]}},"files":{"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\app.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\routes\\Routes.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\AuthController.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Users.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\helpers\\AuthHelper.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\AuthValidator.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\UserController.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\UserValidator.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\LoanController.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Loans.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\LoanValidator.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\RepaymentController.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Repayments.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\RepaymentsValidator.js":["1c4c8f88-0f58-4e63-aba1-3a6c0b920758"]},"externalIds":{}}
{"processes":{"6f6943a7-7cc0-4677-9e66-e4a99ec86260":{"parent":null,"children":["834f7f38-7ab9-4a63-968e-e7d897244774"]},"834f7f38-7ab9-4a63-968e-e7d897244774":{"parent":"6f6943a7-7cc0-4677-9e66-e4a99ec86260","children":[]}},"files":{"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\app.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\routes\\Routes.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\AuthController.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Users.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\helpers\\AuthHelper.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\AuthValidator.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\UserController.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\UserValidator.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\LoanController.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Loans.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\LoanValidator.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\controllers\\RepaymentController.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\models\\Repayments.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\validators\\RepaymentsValidator.js":["834f7f38-7ab9-4a63-968e-e7d897244774"],"C:\\Users\\EXCEL\\Desktop\\Jonathan Stuff\\Quick_credit\\middlewares\\Auth.js":["834f7f38-7ab9-4a63-968e-e7d897244774"]},"externalIds":{}}
37 changes: 36 additions & 1 deletion controllers/LoanController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LoanController {
let loanStatus = queryParimeters['status'];
let loanRepaid = queryParimeters['repaid'];
if (loanRepaid == 'false') { loanRepaid = false }
if (loanRepaid == 'true') { loanRepaid = true }
if (loanRepaid == 'true') { loanRepaid = true }
let sortedData = [];
// sort loan
let sortLoan = loanData.filter((loan) => {
Expand All @@ -54,6 +54,41 @@ class LoanController {
data: sortedData
});
}

loanApplication(req, res) {
const { tenor, amount } = req.body;
const interest = (parseFloat(amount) * 5) / 100;
const balance = parseFloat(amount) + interest;
const payInstallment = (parseFloat(amount) + interest) / tenor;

let newLoanApplication = {
id: loanData.length + 1,
tenor: tenor,
amount: amount,
payInstallment: payInstallment,
status: 'pending',
balance: balance,
interest: interest
}

loanData.push(newLoanApplication);

return res.status(200).json({
status:200,
data: {
loanId: loanData[loanData.length -1].id,
firstName: req.user.firstName,
lastName: req.user.lastName,
email: req.user.email,
tenor: tenor + ' months',
amount: amount,
payInstallment: payInstallment,
status: 'pending',
balance: balance,
interest: interest
}
});
}
}

export default new LoanController;
4 changes: 2 additions & 2 deletions controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class UserController {
let user = userData.find(users => users.email === email);
//mark user as verified
user.status = 'verified';
return res.status(201).json({
status: 201,
return res.status(200).json({
status: 200,
data: user
});
}
Expand Down
2 changes: 1 addition & 1 deletion middlewares/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Auth = {
error: 'The token provide is invalid'
})
}
req.user = { id: decoded.userId };
req.user = user;
next();
});
}
Expand Down
24 changes: 24 additions & 0 deletions middlewares/validators/LoanValidator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

class LoanValidator {
/**
* Method for validating query parimeter
Expand Down Expand Up @@ -37,6 +38,29 @@ class LoanValidator {
}
return next();
}

/**
* Method for validating loan application
* @static
* @param {request} req
* @param {response} res
* @return {obj} return json object.
*/
validateLoanApplication(req, res, next){
const {amount, tenor} = req.body;
let errorMessage = {};

if(isNaN(amount) || (amount < 1000) || (amount > 10000000)) {
errorMessage.amount = 'amount should be number & not less than 1000 or above 10000000';
}
if(isNaN(tenor) || tenor < 1 || tenor > 12){
errorMessage.tenor = 'tenor should be number & not less than 1 or above 12';
}
if (!(Object.keys(errorMessage).length === 0)) {
return res.status(400).json(errorMessage);
}
return next();
}
}

export default new LoanValidator;
4 changes: 2 additions & 2 deletions models/Loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const Loans = [
amount: 21000.00,
paymentInstallment: 6000.00,
balance: 120000,
interest: 6000,
},
interest: 6000
}
];

export default Loans;
26 changes: 26 additions & 0 deletions models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ const Users = [
createdAt: '2/24/2019',
updatedAt: '2/24/2019',
},
{
id: 5,
email: 'timi@gmail.com',
firstName: 'Timi',
lastName: 'Adams',
password: 'password',
address: 'No 20 admans street Lagos Nigeria',
workAddress: 'No 20 admans street Lagos Nigeria',
status: ' verified',
isAdmin: true,
createdAt: '2/24/2019',
updatedAt: '2/24/2019',
},
{
id: 6,
email: 'nathan@gmail.com',
firstName: 'Williams',
lastName: 'Adams',
password: '$2b$08$jqvlFW01BXQI1i.3qzzJIe.NvXCBYSDT/qO6JUJO807k.v0ez67eq',
address: 'No 20 admans street Lagos Nigeria',
workAddress: 'No 20 admans street Lagos Nigeria',
status: ' verified',
isAdmin: true,
createdAt: '2/24/2019',
updatedAt: '2/24/2019',
}
];

export default Users;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"description": "An online lending platform that provides short term soft loans to individuals.",
"main": "index.js",
"scripts": {
"test": "nyc mocha --timeout=3000 --require @babel/register test/tests.js",
"dev-start": "nodemon --exec babel-node app.js"
"test": "nyc --reporter=text mocha --timeout=3000 --require @babel/register --exit test/tests.js",
"dev-start": "nodemon --exec babel-node app.js",
"nyc": "nyc --reporter=lcov npm run test && nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc npm test"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import LoanController from '../controllers/LoanController';
import LoanValidator from '../middlewares/validators/LoanValidator';
import RepaymentController from '../controllers/RepaymentController';
import RepaymentValidator from '../middlewares/validators/RepaymentsValidator';
import Auth from '../middlewares/Auth';


const router = express.Router();
Expand All @@ -23,5 +24,7 @@ router.route('/loans')
.get(LoanValidator.validateQueryParams, LoanController.sortRepaidLoan)
router.route('/loans/:id/repayments')
.get(RepaymentValidator.validateLoanId, RepaymentController.getRepayments);
router.route('/loans')
.post(Auth.verifyToken, LoanValidator.validateLoanApplication, LoanController.loanApplication)

export default router;
Loading