@dynamatix/gb-schemas 0.5.11 → 0.5.12
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.
|
@@ -106,5 +106,17 @@ const applicantSchema = new mongoose.Schema({
|
|
|
106
106
|
income: incomeSchema
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
applicantSchema.virtual('nationality').get(function () {
|
|
110
|
+
return this.nationalityLID ? this.nationalityLID.name : null;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
applicantSchema.virtual('residence').get(function () {
|
|
114
|
+
return this.countryOfResidenceLID ? this.countryOfResidenceLID.name : null;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
applicantSchema.virtual('industry').get(function () {
|
|
118
|
+
return this.employment?.industryLID ? this.employment?.industryLID.name : null;
|
|
119
|
+
});
|
|
120
|
+
applicantSchema.set('toJSON', { virtuals: true });
|
|
109
121
|
const ApplicantModel = mongoose.model("Applicant", applicantSchema);
|
|
110
122
|
export default ApplicantModel;
|
|
@@ -68,8 +68,72 @@ const applicationSchema = new mongoose.Schema(
|
|
|
68
68
|
companyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationCompany", required: true },
|
|
69
69
|
rationaleId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationRationale" }
|
|
70
70
|
},
|
|
71
|
-
{
|
|
71
|
+
{
|
|
72
|
+
timestamps: true,
|
|
73
|
+
toJSON: { virtuals: true },
|
|
74
|
+
toObject: { virtuals: true }
|
|
75
|
+
}
|
|
72
76
|
);
|
|
73
77
|
|
|
78
|
+
|
|
79
|
+
// Virtual property 'noOfApplicants'
|
|
80
|
+
applicationSchema.virtual('noOfApplicants').get(function() {
|
|
81
|
+
return this.applicants ? this.applicants.length : 0;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Virtual property 'applicationTypeName'
|
|
85
|
+
applicationSchema.virtual('applicationTypeName').get(function() {
|
|
86
|
+
return this.applicationTypeLID ? this.applicationTypeLID.name : null;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Virtual property 'LTV %'
|
|
90
|
+
applicationSchema.virtual('ltv').get(function() {
|
|
91
|
+
const purchasePrice = this.mortgage?.purchasePrice;
|
|
92
|
+
const loanRequired = this.mortgage?.loanRequired;
|
|
93
|
+
|
|
94
|
+
if (purchasePrice && loanRequired) {
|
|
95
|
+
const parseCurrency = (value) => {
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
return parseFloat(value.replace(/[^0-9.-]+/g, ""));
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const parsedPurchasePrice = parseCurrency(purchasePrice);
|
|
103
|
+
const parsedLoanRequired = parseCurrency(loanRequired);
|
|
104
|
+
const ltv = (parsedLoanRequired / parsedPurchasePrice) * 100;
|
|
105
|
+
return ltv.toFixed(2)+"%";
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
applicationSchema.virtual('submittedDateFormatted').get(function() {
|
|
111
|
+
if (!this.submittedDate) return null;
|
|
112
|
+
const day = String(this.submittedDate.getDate()).padStart(2, '0');
|
|
113
|
+
const month = String(this.submittedDate.getMonth() + 1).padStart(2, '0');
|
|
114
|
+
const year = this.submittedDate.getFullYear();
|
|
115
|
+
return `${day}-${month}-${year}`;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Virtual property for broker name
|
|
119
|
+
applicationSchema.virtual('brokerName').get(function() {
|
|
120
|
+
return this.brokerID ? this.brokerID?.firstName : null;
|
|
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
|
+
|
|
74
138
|
const ApplicationModel = mongoose.model("Application", applicationSchema);
|
|
75
139
|
export default ApplicationModel;
|
package/package.json
CHANGED
|
@@ -93,7 +93,21 @@ const propertySchema = new mongoose.Schema({
|
|
|
93
93
|
energyEfficiencyRating: { type: String},
|
|
94
94
|
energyEfficiencyRatingValue: { type: Number },
|
|
95
95
|
dataStreetSchema: dataStreetSchema,
|
|
96
|
-
}
|
|
96
|
+
}, {
|
|
97
|
+
toJSON: { virtuals: true },
|
|
98
|
+
toObject: { virtuals: true }
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// virtual property 'tenure'
|
|
103
|
+
propertySchema.virtual('tenure').get(function () {
|
|
104
|
+
return this.propertyTenureLID ? this.propertyTenureLID.name : null;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// virtual property 'type'
|
|
108
|
+
propertySchema.virtual('type').get(function () {
|
|
109
|
+
return this.propertyTypeLID ? this.propertyTypeLID.name : null;
|
|
110
|
+
});
|
|
97
111
|
|
|
98
112
|
const PropertyModel = mongoose.model("Property", propertySchema);
|
|
99
113
|
export default PropertyModel;
|