Created
December 1, 2019 02:47
-
-
Save intojs/6dc387de9863c2bb23052c6c0acfce20 to your computer and use it in GitHub Desktop.
Loan Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context.initialize({ | |
loanRepo: new InMemoryLoanRepo(), | |
emailServ: new InMemoryEmailServ(), | |
}); | |
const schema = Joi.object({ | |
emailAddress: Joi | |
.string() | |
.email() | |
.required(), | |
loanAmount: Joi | |
.number() | |
.min(LoanAmount.min) | |
.max(LoanAmount.max) | |
.required(), | |
loanTerm: Joi | |
.number() | |
.min(LoanTerm.min) | |
.max(LoanTerm.max) | |
.required(), | |
lifeInsuranceOptIn: Joi.bool(), | |
}); | |
const loanRouter = express.Router(); | |
loanRouter.post('/calculate', async (req, res) => { | |
try { | |
const { error, value } = Joi.validate(req.body, schema); | |
if (error) { | |
res.status(BAD_REQUEST).send(error); | |
return; | |
} | |
const calculation: CalculateLoanRes = await calculateLoan(value); | |
res.send(calculation); | |
} catch (e) { | |
res.status(INTERNAL_SERVER_ERROR).send(e); | |
} | |
}); | |
export { loanRouter }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment