@dynamatix/gb-schemas 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/applications/application.model.js +137 -137
- package/package.json +1 -1
|
@@ -4,146 +4,146 @@ import creditProfileSchema from "./application-credit-profile.model.js";
|
|
|
4
4
|
import mortgageSchema from "./application-mortgage.model.js";
|
|
5
5
|
|
|
6
6
|
const applicationSchema = new mongoose.Schema(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
7
|
+
{
|
|
8
|
+
queueId: [{
|
|
9
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
10
|
+
ref: "Queue",
|
|
11
|
+
required: true,
|
|
12
|
+
}],
|
|
13
|
+
assignedToUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
|
|
14
|
+
applicationId: { type: String, required: true },
|
|
15
|
+
isApplicationFeePaid: { type: Boolean, required: true },
|
|
16
|
+
applicationNumber: { type: String, required: true },
|
|
17
|
+
applicationTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
18
|
+
bankSolicitor: { type: String, default: "" },
|
|
19
|
+
brokerId: { type: mongoose.Schema.Types.ObjectId, ref: "Broker", required: true },
|
|
20
|
+
caseManager: { type: String, default: "" },
|
|
21
|
+
caseManagerAccepted: { type: Boolean, default: false },
|
|
22
|
+
completedReason: { type: String, default: "" },
|
|
23
|
+
isIntendToOccupy: { type: Boolean, required: true },
|
|
24
|
+
introducer: { type: String, default: "" },
|
|
25
|
+
isIntroducerSubmission: { type: Boolean, required: true },
|
|
26
|
+
isBrokerAssigned: { type: Boolean, default: false },
|
|
27
|
+
isFinanceRecommendedToApplicant: { type: Boolean, required: true },
|
|
28
|
+
isWorkflowTaskCreated: { type: Boolean, required: true },
|
|
29
|
+
lastUpdated: { type: Date },
|
|
30
|
+
lendingTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
31
|
+
networkClubName: { type: String, default: "" },
|
|
32
|
+
isNetworkClubSubmission: { type: Boolean, required: true },
|
|
33
|
+
newReason: { type: String, default: "" },
|
|
34
|
+
purchaseTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
35
|
+
rejectedReason: { type: String, default: "" },
|
|
36
|
+
repaymentTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
37
|
+
selectedProduct: { type: String, required: true },
|
|
38
|
+
sourceOfWealthLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
39
|
+
sowBusiness: { type: String, default: "" },
|
|
40
|
+
sowInheritance: { type: String, default: "" },
|
|
41
|
+
sowOther: { type: String, default: "" },
|
|
42
|
+
sowProperty: { type: String, default: "" },
|
|
43
|
+
sowSalary: { type: String, default: "" },
|
|
44
|
+
statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
45
|
+
submitReason: { type: String, default: "" },
|
|
46
|
+
submittedDate: { type: Date },
|
|
47
|
+
underwriter: { type: String, default: "" },
|
|
48
|
+
isValuationFeePaid: { type: Boolean, required: true },
|
|
49
|
+
withdrawalReason: { type: String, default: "" },
|
|
50
|
+
withdrawalReasonCode: { type: String, default: "" },
|
|
51
|
+
productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product", required: true },
|
|
52
|
+
product: { type: String },
|
|
53
|
+
propertyId: { type: mongoose.Schema.Types.ObjectId, ref: "Property", required: true },
|
|
54
|
+
solicitorId: { type: mongoose.Schema.Types.ObjectId, ref: "Solicitor", required: true },
|
|
55
|
+
applicants: [
|
|
56
|
+
{ type: mongoose.Schema.Types.ObjectId, ref: "Applicant" }
|
|
57
|
+
],
|
|
58
|
+
statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
|
|
59
|
+
submittedDate: { type: Date },
|
|
60
|
+
isValuationFeePaid: { type: Boolean, required: true },
|
|
61
|
+
isActive: { type: Boolean, default: false },
|
|
62
|
+
isUkResident: { type: Boolean, default: true },
|
|
63
|
+
riskRating: { type: String },
|
|
64
|
+
directDebit: directDebitSchema,
|
|
65
|
+
creditProfile: creditProfileSchema,
|
|
66
|
+
mortgage: mortgageSchema,
|
|
67
|
+
companyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationCompany", required: true },
|
|
68
|
+
rationaleId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationRationale" }
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
timestamps: true,
|
|
72
|
+
toJSON: { virtuals: true },
|
|
73
|
+
toObject: { virtuals: true }
|
|
74
|
+
}
|
|
76
75
|
);
|
|
77
76
|
|
|
78
77
|
|
|
79
78
|
// Virtual property 'noOfApplicants'
|
|
80
|
-
applicationSchema.virtual('noOfApplicants').get(function() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
79
|
+
applicationSchema.virtual('noOfApplicants').get(function () {
|
|
80
|
+
return this.applicants ? this.applicants.length : 0;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Virtual property 'applicationTypeName'
|
|
84
|
+
applicationSchema.virtual('applicationTypeName').get(function () {
|
|
85
|
+
return this.applicationTypeLid ? this.applicationTypeLid.name : null;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Virtual property 'LTV %'
|
|
89
|
+
applicationSchema.virtual('ltv').get(function () {
|
|
90
|
+
const purchasePrice = this.mortgage?.purchasePrice;
|
|
91
|
+
const loanRequired = this.mortgage?.loanRequired;
|
|
92
|
+
|
|
93
|
+
if (purchasePrice && loanRequired) {
|
|
94
|
+
const parseCurrency = (value) => {
|
|
95
|
+
if (typeof value === 'string') {
|
|
96
|
+
return parseFloat(value.replace(/[^0-9.-]+/g, ""));
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const parsedPurchasePrice = parseCurrency(purchasePrice);
|
|
102
|
+
const parsedLoanRequired = parseCurrency(loanRequired);
|
|
103
|
+
const ltv = (parsedLoanRequired / parsedPurchasePrice) * 100;
|
|
104
|
+
return ltv.toFixed(2) + "%";
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
applicationSchema.virtual('submittedDateFormatted').get(function () {
|
|
110
|
+
if (!this.submittedDate) return null;
|
|
111
|
+
const day = String(this.submittedDate.getDate()).padStart(2, '0');
|
|
112
|
+
const month = String(this.submittedDate.getMonth() + 1).padStart(2, '0');
|
|
113
|
+
const year = this.submittedDate.getFullYear();
|
|
114
|
+
return `${day}-${month}-${year}`;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Virtual property for broker name
|
|
118
|
+
applicationSchema.virtual('brokerName').get(function () {
|
|
119
|
+
if (!this.brokerId?.firstName || !this.brokerId?.lastName) return null;
|
|
120
|
+
return this.brokerId.firstName + " " + this.brokerId.lastName;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Virtual property for broker email
|
|
124
|
+
applicationSchema.virtual('brokerEmail').get(function () {
|
|
125
|
+
return this.brokerId ? this.brokerId?.email : null;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Virtual property for solicitor name
|
|
129
|
+
applicationSchema.virtual('solicitorName').get(function () {
|
|
130
|
+
return this.solicitorId ? this.solicitorId?.nameOfAccountHolder : null;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Virtual property for solicitor email
|
|
134
|
+
applicationSchema.virtual('solicitorEmail').get(function () {
|
|
135
|
+
return this.solicitorId ? this.solicitorId?.email : null;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Virtual property for broker phone
|
|
139
|
+
applicationSchema.virtual('brokerPhone').get(function () {
|
|
140
|
+
return this.brokerId ? this.brokerId?.mobileTelephone : null;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Virtual property for solicitor phone
|
|
144
|
+
applicationSchema.virtual('solicitorPhone').get(function () {
|
|
145
|
+
return this.solicitorId ? this.solicitorId?.telephone : null;
|
|
146
|
+
});
|
|
137
147
|
|
|
138
|
-
// Virtual property for broker phone
|
|
139
|
-
applicationSchema.virtual('brokerPhone').get(function () {
|
|
140
|
-
return this.brokerId ? this.brokerId?.mobileTelephone : null;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Virtual property for solicitor phone
|
|
144
|
-
applicationSchema.virtual('solicitorPhone').get(function () {
|
|
145
|
-
return this.solicitorId ? this.solicitorId?.telephone : null;
|
|
146
|
-
});
|
|
147
|
-
|
|
148
148
|
const ApplicationModel = mongoose.model("Application", applicationSchema);
|
|
149
|
-
export default ApplicationModel;
|
|
149
|
+
export default ApplicationModel;
|