Skip to content

Instantly share code, notes, and snippets.

@intojs
Created December 1, 2019 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intojs/6dc387de9863c2bb23052c6c0acfce20 to your computer and use it in GitHub Desktop.
Save intojs/6dc387de9863c2bb23052c6c0acfce20 to your computer and use it in GitHub Desktop.
Loan Router
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