Skip to content

Instantly share code, notes, and snippets.

@ayende
Created February 27, 2019 08:29
Show Gist options
  • Save ayende/8e84512fb81950b28da248abd5753c8a to your computer and use it in GitHub Desktop.
Save ayende/8e84512fb81950b28da248abd5753c8a to your computer and use it in GitHub Desktop.
on("init", () => {
var state = {
Status: "New"
};
return state;
});
on("loan-submission", (state, req) => {
state.Amount = req.Amount;
if(req.CreditScore < 500) {
state.Status = "Denied";
return "Credit score too low";
}
if(req.Amount < 1000) {
state.Status = "Approved";
return "Credit score is good and loan amount is small";
}
if(req.LifeInsurance == null) {
state.Status = next("life-insurance-setup");
return;
}
state.Status = next("compute-apr");
return;
});
on("life-insurance-setup", (state, req) => {
if(req.Denied){
state.Status = "Denied";
return "Cannot get a loan for this ammount without life insurance";
}
state.Status = next("compute-apr");
});
on("compute-apr", (state, req) => {
if(req.APR > 25) {
state.Status = "Denied";
return "Better to refuse the loan than handle usury charges";
}
state.Status = next("offer-to-user");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment