@dynamatix/gb-schemas 0.8.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.
@@ -100,23 +100,59 @@ const applicantSchema = new mongoose.Schema({
100
100
  incomeSource: applicantIncomeSourceSchema,
101
101
  expenditure: applicantExpenditureSchema,
102
102
  employment: applicantEmploymentSchema,
103
- commitments:[applicantCommitmentSchema],
103
+ commitments: [applicantCommitmentSchema],
104
104
  directDebit: applicantDirectDebitSchema,
105
105
  creditProfile: creditProfileSchema,
106
106
  income: incomeSchema
107
+ }, {
108
+ timestamps: true,
109
+ toJSON: { virtuals: true },
110
+ toObject: { virtuals: true }
107
111
  });
108
112
 
109
113
  applicantSchema.virtual('nationality').get(function () {
110
- return this.nationalityLid ? this.nationalityLid.name : null;
114
+ return this.nationalityLid?.name ?? null;
111
115
  });
112
116
 
113
117
  applicantSchema.virtual('residence').get(function () {
114
- return this.countryOfResidenceLid ? this.countryOfResidenceLid.name : null;
118
+ return this.countryOfResidenceLid?.name ?? null;
115
119
  });
116
120
 
117
121
  applicantSchema.virtual('industry').get(function () {
118
- return this.employment?.industryLid ? this.employment?.industryLid.name : null;
122
+ return this.employment?.industryLid ? this.employment?.industryLid?.name : null;
119
123
  });
120
- applicantSchema.set('toJSON', { virtuals: true });
124
+
125
+ applicantSchema.virtual('addressCountry').get(function () {
126
+ return this.addressCountryLid?.name ?? null;
127
+ });
128
+
129
+ applicantSchema.virtual('previous1AddressCountry').get(function () {
130
+ return this.previous1AddressCountryLid?.name ?? null;
131
+ });
132
+
133
+ applicantSchema.virtual('previous2AddressCountry').get(function () {
134
+ return this.previous2AddressCountryLid?.name ?? null;
135
+ });
136
+
137
+ applicantSchema.virtual('maritalStatus').get(function () {
138
+ return this.maritalStatusLid?.name ?? null;
139
+ });
140
+
141
+ applicantSchema.virtual('relationshipToOthers').get(function () {
142
+ return this.relationshipToOthersLid?.name ?? null;
143
+ });
144
+
145
+ applicantSchema.virtual('residentialStatus').get(function () {
146
+ return this.residentialStatusLid?.name ?? null;
147
+ });
148
+
149
+ applicantSchema.virtual('taxPayer').get(function () {
150
+ return this.taxPayerLid?.name ?? null;
151
+ });
152
+
153
+ applicantSchema.virtual('vulnerabilityType').get(function () {
154
+ return this.VulnerabilityTypeLid?.name ?? null;
155
+ });
156
+
121
157
  const ApplicantModel = mongoose.model("Applicant", applicantSchema);
122
- export default ApplicantModel;
158
+ export default ApplicantModel;
@@ -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
- 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
- brokerName: { type: String }, // Broker name field added
21
- caseManager: { type: String, default: "" },
22
- caseManagerAccepted: { type: Boolean, default: false },
23
- completedReason: { type: String, default: "" },
24
- isIntendToOccupy: { type: Boolean, required: true },
25
- introducer: { type: String, default: "" },
26
- isIntroducerSubmission: { type: Boolean, required: true },
27
- isBrokerAssigned: { type: Boolean, default: false },
28
- isFinanceRecommendedToApplicant: { type: Boolean, required: true },
29
- isWorkflowTaskCreated: { type: Boolean, required: true },
30
- lastUpdated: { type: Date },
31
- lendingTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
32
- networkClubName: { type: String, default: "" },
33
- isNetworkClubSubmission: { type: Boolean, required: true },
34
- newReason: { type: String, default: "" },
35
- purchaseTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
36
- rejectedReason: { type: String, default: "" },
37
- repaymentTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
38
- selectedProduct: { type: String, required: true },
39
- sourceOfWealthLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
40
- sowBusiness: { type: String, default: "" },
41
- sowInheritance: { type: String, default: "" },
42
- sowOther: { type: String, default: "" },
43
- sowProperty: { type: String, default: "" },
44
- sowSalary: { type: String, default: "" },
45
- statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
46
- submitReason: { type: String, default: "" },
47
- submittedDate: { type: Date },
48
- underwriter: { type: String, default: "" },
49
- isValuationFeePaid: { type: Boolean, required: true },
50
- withdrawalReason: { type: String, default: "" },
51
- withdrawalReasonCode: { type: String, default: "" },
52
- productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product", required: true },
53
- product: { type: String },
54
- propertyId: { type: mongoose.Schema.Types.ObjectId, ref: "Property", required: true },
55
- solicitorId: { type: mongoose.Schema.Types.ObjectId, ref: "Solicitor", required: true },
56
- applicants: [
57
- { type: mongoose.Schema.Types.ObjectId, ref: "Applicant" }
58
- ],
59
- statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", required: true },
60
- submittedDate: { type: Date },
61
- isValuationFeePaid: { type: Boolean, required: true },
62
- isActive: { type: Boolean, default: false },
63
- isUkResident: { type: Boolean, default: true },
64
- riskRating: { type: String },
65
- directDebit: directDebitSchema,
66
- creditProfile: creditProfileSchema,
67
- mortgage: mortgageSchema,
68
- companyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationCompany", required: true },
69
- rationaleId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationRationale" }
70
- },
71
- {
72
- timestamps: true,
73
- toJSON: { virtuals: true },
74
- toObject: { virtuals: true }
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
- 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('brokerFirstName').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
- });
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "All the schemas for gatehouse bank back-end",
5
5
  "main": "index.js",
6
6
  "scripts": {