Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e94d865

Browse files
author
Andrey Leybovich
committedJun 1, 2024
adding loan approval workflow example
1 parent 080d35e commit e94d865

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed
 

‎rules/loan_approval.yaml

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
scripts: |
2+
function isPrimaryApplicant(applicant) {
3+
return applicant.Type === 'primary';
4+
}
5+
6+
function hasCoApplicant(applicants) {
7+
return applicants.some(a => a.Type === 'co-applicant');
8+
}
9+
10+
function getTotalIncome(applicants) {
11+
return applicants.reduce((sum, a) => sum + a.Income, 0);
12+
}
13+
14+
function getTotalDebt(applicants) {
15+
return applicants.reduce((sum, a) => sum + a.Debt, 0);
16+
}
17+
18+
function getDebtToIncomeRatio(applicants) {
19+
const totalIncome = getTotalIncome(applicants);
20+
const totalDebt = getTotalDebt(applicants);
21+
return totalIncome > 0 ? totalDebt / totalIncome : Infinity;
22+
}
23+
24+
conditions:
25+
check_primary_applicant:
26+
description: Check if there is a primary applicant
27+
default: true
28+
check: |
29+
function () {
30+
return context.Applicants.some(isPrimaryApplicant);
31+
}
32+
true:
33+
next: check_applicant_age
34+
false:
35+
description: Reject the loan application due to missing primary applicant
36+
action: |
37+
function () {
38+
context.Decision = 'rejected';
39+
context.Reason = 'No primary applicant';
40+
}
41+
terminate: true
42+
43+
check_applicant_age:
44+
description: Check if the primary applicant is at least 18 years old
45+
check: |
46+
function () {
47+
const primaryApplicant = context.Applicants.find(isPrimaryApplicant);
48+
return primaryApplicant.Age >= 18;
49+
}
50+
true:
51+
next: check_applicant_income
52+
false:
53+
description: Reject the loan application due to underage primary applicant
54+
action: |
55+
function () {
56+
context.Decision = 'rejected';
57+
context.Reason = 'Primary applicant is underage';
58+
}
59+
terminate: true
60+
61+
check_applicant_income:
62+
description: Check if the primary applicant's income is at least $1,000
63+
check: |
64+
function () {
65+
const primaryApplicant = context.Applicants.find(isPrimaryApplicant);
66+
return primaryApplicant.Income >= 1000;
67+
}
68+
true:
69+
next: check_applicant_credit_score
70+
false:
71+
description: Reject the loan application due to insufficient income
72+
action: |
73+
function () {
74+
context.Decision = 'rejected';
75+
context.Reason = 'Insufficient income';
76+
}
77+
terminate: true
78+
79+
check_applicant_credit_score:
80+
description: Check if the primary applicant's credit score is at least 600
81+
check: |
82+
function () {
83+
const primaryApplicant = context.Applicants.find(isPrimaryApplicant);
84+
return primaryApplicant.CreditScore >= 600;
85+
}
86+
true:
87+
next: check_co_applicant
88+
false:
89+
description: Reject the loan application due to low credit score
90+
action: |
91+
function () {
92+
context.Decision = 'rejected';
93+
context.Reason = 'Low credit score';
94+
}
95+
terminate: true
96+
97+
check_co_applicant:
98+
description: Check if there is a co-applicant
99+
check: |
100+
function () {
101+
return hasCoApplicant(context.Applicants);
102+
}
103+
true:
104+
next: check_co_applicant_age
105+
false:
106+
next: check_debt_to_income_ratio
107+
108+
check_co_applicant_age:
109+
description: Check if the co-applicant is at least 18 years old
110+
check: |
111+
function () {
112+
const coApplicant = context.Applicants.find(a => a.Type === 'co-applicant');
113+
return coApplicant.Age >= 18;
114+
}
115+
true:
116+
next: check_co_applicant_credit_score
117+
false:
118+
description: Reject the loan application due to underage co-applicant
119+
action: |
120+
function () {
121+
context.Decision = 'rejected';
122+
context.Reason = 'Co-applicant is underage';
123+
}
124+
terminate: true
125+
126+
check_co_applicant_credit_score:
127+
description: Check if the co-applicant's credit score is at least 600
128+
check: |
129+
function () {
130+
const coApplicant = context.Applicants.find(a => a.Type === 'co-applicant');
131+
return coApplicant.CreditScore >= 600;
132+
}
133+
true:
134+
next: check_debt_to_income_ratio
135+
false:
136+
description: Reject the loan application due to co-applicant's low credit score
137+
action: |
138+
function () {
139+
context.Decision = 'rejected';
140+
context.Reason = 'Co-applicant has low credit score';
141+
}
142+
terminate: true
143+
144+
check_debt_to_income_ratio:
145+
description: Check if the debt-to-income ratio is less than or equal to 36%
146+
check: |
147+
function () {
148+
return getDebtToIncomeRatio(context.Applicants) <= 0.36;
149+
}
150+
true:
151+
next: check_loan_amount
152+
false:
153+
description: Reject the loan application due to high debt-to-income ratio
154+
action: |
155+
function () {
156+
context.Decision = 'rejected';
157+
context.Reason = 'High debt-to-income ratio';
158+
}
159+
terminate: true
160+
161+
check_loan_amount:
162+
description: Check if the loan amount is less than or equal to 5 times the total income
163+
check: |
164+
function () {
165+
const totalIncome = getTotalIncome(context.Applicants);
166+
return context.LoanAmount <= 5 * totalIncome;
167+
}
168+
true:
169+
description: Approve the loan application
170+
action: |
171+
function () {
172+
context.Decision = 'approved';
173+
}
174+
terminate: true
175+
false:
176+
description: Reject the loan application due to excessive loan amount
177+
action: |
178+
function () {
179+
context.Decision = 'rejected';
180+
context.Reason = 'Excessive loan amount';
181+
}
182+
terminate: true

0 commit comments

Comments
 (0)
Please sign in to comment.