@dynamatix/gb-schemas 2.3.394 → 2.3.395

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.
@@ -542,9 +542,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
542
542
  address?: {
543
543
  number: string;
544
544
  street: string;
545
+ county: string;
545
546
  postcode: string;
546
547
  postTown: string;
547
- county: string;
548
548
  addressId: string;
549
549
  } | null | undefined;
550
550
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -552,9 +552,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
552
552
  address?: {
553
553
  number: string;
554
554
  street: string;
555
+ county: string;
555
556
  postcode: string;
556
557
  postTown: string;
557
- county: string;
558
558
  addressId: string;
559
559
  } | null | undefined;
560
560
  }> & {
@@ -562,9 +562,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
562
562
  address?: {
563
563
  number: string;
564
564
  street: string;
565
+ county: string;
565
566
  postcode: string;
566
567
  postTown: string;
567
- county: string;
568
568
  addressId: string;
569
569
  } | null | undefined;
570
570
  }>;
@@ -572,27 +572,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
572
572
  address?: {
573
573
  number: string;
574
574
  name: string;
575
- country: string;
576
575
  postcode: string;
577
576
  postTown: string;
577
+ country: string;
578
578
  street1: string;
579
579
  } | null | undefined;
580
580
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
581
581
  address?: {
582
582
  number: string;
583
583
  name: string;
584
- country: string;
585
584
  postcode: string;
586
585
  postTown: string;
586
+ country: string;
587
587
  street1: string;
588
588
  } | null | undefined;
589
589
  }> & {
590
590
  address?: {
591
591
  number: string;
592
592
  name: string;
593
- country: string;
594
593
  postcode: string;
595
594
  postTown: string;
595
+ country: string;
596
596
  street1: string;
597
597
  } | null | undefined;
598
598
  }>;
@@ -1166,9 +1166,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1166
1166
  address?: {
1167
1167
  number: string;
1168
1168
  street: string;
1169
+ county: string;
1169
1170
  postcode: string;
1170
1171
  postTown: string;
1171
- county: string;
1172
1172
  addressId: string;
1173
1173
  } | null | undefined;
1174
1174
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -1176,9 +1176,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1176
1176
  address?: {
1177
1177
  number: string;
1178
1178
  street: string;
1179
+ county: string;
1179
1180
  postcode: string;
1180
1181
  postTown: string;
1181
- county: string;
1182
1182
  addressId: string;
1183
1183
  } | null | undefined;
1184
1184
  }> & {
@@ -1186,9 +1186,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1186
1186
  address?: {
1187
1187
  number: string;
1188
1188
  street: string;
1189
+ county: string;
1189
1190
  postcode: string;
1190
1191
  postTown: string;
1191
- county: string;
1192
1192
  addressId: string;
1193
1193
  } | null | undefined;
1194
1194
  }>;
@@ -1196,27 +1196,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1196
1196
  address?: {
1197
1197
  number: string;
1198
1198
  name: string;
1199
- country: string;
1200
1199
  postcode: string;
1201
1200
  postTown: string;
1201
+ country: string;
1202
1202
  street1: string;
1203
1203
  } | null | undefined;
1204
1204
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
1205
1205
  address?: {
1206
1206
  number: string;
1207
1207
  name: string;
1208
- country: string;
1209
1208
  postcode: string;
1210
1209
  postTown: string;
1210
+ country: string;
1211
1211
  street1: string;
1212
1212
  } | null | undefined;
1213
1213
  }> & {
1214
1214
  address?: {
1215
1215
  number: string;
1216
1216
  name: string;
1217
- country: string;
1218
1217
  postcode: string;
1219
1218
  postTown: string;
1219
+ country: string;
1220
1220
  street1: string;
1221
1221
  } | null | undefined;
1222
1222
  }>;
@@ -1790,9 +1790,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1790
1790
  address?: {
1791
1791
  number: string;
1792
1792
  street: string;
1793
+ county: string;
1793
1794
  postcode: string;
1794
1795
  postTown: string;
1795
- county: string;
1796
1796
  addressId: string;
1797
1797
  } | null | undefined;
1798
1798
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -1800,9 +1800,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1800
1800
  address?: {
1801
1801
  number: string;
1802
1802
  street: string;
1803
+ county: string;
1803
1804
  postcode: string;
1804
1805
  postTown: string;
1805
- county: string;
1806
1806
  addressId: string;
1807
1807
  } | null | undefined;
1808
1808
  }> & {
@@ -1810,9 +1810,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1810
1810
  address?: {
1811
1811
  number: string;
1812
1812
  street: string;
1813
+ county: string;
1813
1814
  postcode: string;
1814
1815
  postTown: string;
1815
- county: string;
1816
1816
  addressId: string;
1817
1817
  } | null | undefined;
1818
1818
  }>;
@@ -1820,27 +1820,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
1820
1820
  address?: {
1821
1821
  number: string;
1822
1822
  name: string;
1823
- country: string;
1824
1823
  postcode: string;
1825
1824
  postTown: string;
1825
+ country: string;
1826
1826
  street1: string;
1827
1827
  } | null | undefined;
1828
1828
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
1829
1829
  address?: {
1830
1830
  number: string;
1831
1831
  name: string;
1832
- country: string;
1833
1832
  postcode: string;
1834
1833
  postTown: string;
1834
+ country: string;
1835
1835
  street1: string;
1836
1836
  } | null | undefined;
1837
1837
  }> & {
1838
1838
  address?: {
1839
1839
  number: string;
1840
1840
  name: string;
1841
- country: string;
1842
1841
  postcode: string;
1843
1842
  postTown: string;
1843
+ country: string;
1844
1844
  street1: string;
1845
1845
  } | null | undefined;
1846
1846
  }>;
@@ -2418,9 +2418,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
2418
2418
  address?: {
2419
2419
  number: string;
2420
2420
  street: string;
2421
+ county: string;
2421
2422
  postcode: string;
2422
2423
  postTown: string;
2423
- county: string;
2424
2424
  addressId: string;
2425
2425
  } | null | undefined;
2426
2426
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -2428,9 +2428,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
2428
2428
  address?: {
2429
2429
  number: string;
2430
2430
  street: string;
2431
+ county: string;
2431
2432
  postcode: string;
2432
2433
  postTown: string;
2433
- county: string;
2434
2434
  addressId: string;
2435
2435
  } | null | undefined;
2436
2436
  }> & {
@@ -2438,9 +2438,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
2438
2438
  address?: {
2439
2439
  number: string;
2440
2440
  street: string;
2441
+ county: string;
2441
2442
  postcode: string;
2442
2443
  postTown: string;
2443
- county: string;
2444
2444
  addressId: string;
2445
2445
  } | null | undefined;
2446
2446
  }>;
@@ -2448,27 +2448,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
2448
2448
  address?: {
2449
2449
  number: string;
2450
2450
  name: string;
2451
- country: string;
2452
2451
  postcode: string;
2453
2452
  postTown: string;
2453
+ country: string;
2454
2454
  street1: string;
2455
2455
  } | null | undefined;
2456
2456
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
2457
2457
  address?: {
2458
2458
  number: string;
2459
2459
  name: string;
2460
- country: string;
2461
2460
  postcode: string;
2462
2461
  postTown: string;
2462
+ country: string;
2463
2463
  street1: string;
2464
2464
  } | null | undefined;
2465
2465
  }> & {
2466
2466
  address?: {
2467
2467
  number: string;
2468
2468
  name: string;
2469
- country: string;
2470
2469
  postcode: string;
2471
2470
  postTown: string;
2471
+ country: string;
2472
2472
  street1: string;
2473
2473
  } | null | undefined;
2474
2474
  }>;
@@ -3042,9 +3042,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3042
3042
  address?: {
3043
3043
  number: string;
3044
3044
  street: string;
3045
+ county: string;
3045
3046
  postcode: string;
3046
3047
  postTown: string;
3047
- county: string;
3048
3048
  addressId: string;
3049
3049
  } | null | undefined;
3050
3050
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -3052,9 +3052,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3052
3052
  address?: {
3053
3053
  number: string;
3054
3054
  street: string;
3055
+ county: string;
3055
3056
  postcode: string;
3056
3057
  postTown: string;
3057
- county: string;
3058
3058
  addressId: string;
3059
3059
  } | null | undefined;
3060
3060
  }> & {
@@ -3062,9 +3062,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3062
3062
  address?: {
3063
3063
  number: string;
3064
3064
  street: string;
3065
+ county: string;
3065
3066
  postcode: string;
3066
3067
  postTown: string;
3067
- county: string;
3068
3068
  addressId: string;
3069
3069
  } | null | undefined;
3070
3070
  }>;
@@ -3072,27 +3072,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3072
3072
  address?: {
3073
3073
  number: string;
3074
3074
  name: string;
3075
- country: string;
3076
3075
  postcode: string;
3077
3076
  postTown: string;
3077
+ country: string;
3078
3078
  street1: string;
3079
3079
  } | null | undefined;
3080
3080
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
3081
3081
  address?: {
3082
3082
  number: string;
3083
3083
  name: string;
3084
- country: string;
3085
3084
  postcode: string;
3086
3085
  postTown: string;
3086
+ country: string;
3087
3087
  street1: string;
3088
3088
  } | null | undefined;
3089
3089
  }> & {
3090
3090
  address?: {
3091
3091
  number: string;
3092
3092
  name: string;
3093
- country: string;
3094
3093
  postcode: string;
3095
3094
  postTown: string;
3095
+ country: string;
3096
3096
  street1: string;
3097
3097
  } | null | undefined;
3098
3098
  }>;
@@ -3666,9 +3666,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3666
3666
  address?: {
3667
3667
  number: string;
3668
3668
  street: string;
3669
+ county: string;
3669
3670
  postcode: string;
3670
3671
  postTown: string;
3671
- county: string;
3672
3672
  addressId: string;
3673
3673
  } | null | undefined;
3674
3674
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
@@ -3676,9 +3676,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3676
3676
  address?: {
3677
3677
  number: string;
3678
3678
  street: string;
3679
+ county: string;
3679
3680
  postcode: string;
3680
3681
  postTown: string;
3681
- county: string;
3682
3682
  addressId: string;
3683
3683
  } | null | undefined;
3684
3684
  }> & {
@@ -3686,9 +3686,9 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3686
3686
  address?: {
3687
3687
  number: string;
3688
3688
  street: string;
3689
+ county: string;
3689
3690
  postcode: string;
3690
3691
  postTown: string;
3691
- county: string;
3692
3692
  addressId: string;
3693
3693
  } | null | undefined;
3694
3694
  }>;
@@ -3696,27 +3696,27 @@ declare const ApplicantCreditReportModel: mongoose.Model<{
3696
3696
  address?: {
3697
3697
  number: string;
3698
3698
  name: string;
3699
- country: string;
3700
3699
  postcode: string;
3701
3700
  postTown: string;
3701
+ country: string;
3702
3702
  street1: string;
3703
3703
  } | null | undefined;
3704
3704
  }, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
3705
3705
  address?: {
3706
3706
  number: string;
3707
3707
  name: string;
3708
- country: string;
3709
3708
  postcode: string;
3710
3709
  postTown: string;
3710
+ country: string;
3711
3711
  street1: string;
3712
3712
  } | null | undefined;
3713
3713
  }> & {
3714
3714
  address?: {
3715
3715
  number: string;
3716
3716
  name: string;
3717
- country: string;
3718
3717
  postcode: string;
3719
3718
  postTown: string;
3719
+ country: string;
3720
3720
  street1: string;
3721
3721
  } | null | undefined;
3722
3722
  }>;
@@ -584,7 +584,7 @@ declare const ApplicationDirectDebitModel: mongoose.Model<{
584
584
  buildingName?: string | null | undefined;
585
585
  buildingNumber?: string | null | undefined;
586
586
  street?: string | null | undefined;
587
- country?: string | null | undefined;
587
+ county?: string | null | undefined;
588
588
  postcode?: string | null | undefined;
589
589
  } | null | undefined;
590
590
  } | null | undefined;
@@ -631,7 +631,7 @@ declare const ApplicationDirectDebitModel: mongoose.Model<{
631
631
  buildingName?: string | null | undefined;
632
632
  buildingNumber?: string | null | undefined;
633
633
  street?: string | null | undefined;
634
- country?: string | null | undefined;
634
+ county?: string | null | undefined;
635
635
  postcode?: string | null | undefined;
636
636
  } | null | undefined;
637
637
  } | null | undefined;
@@ -678,7 +678,7 @@ declare const ApplicationDirectDebitModel: mongoose.Model<{
678
678
  buildingName?: string | null | undefined;
679
679
  buildingNumber?: string | null | undefined;
680
680
  street?: string | null | undefined;
681
- country?: string | null | undefined;
681
+ county?: string | null | undefined;
682
682
  postcode?: string | null | undefined;
683
683
  } | null | undefined;
684
684
  } | null | undefined;
@@ -1,148 +1,155 @@
1
- import mongoose from 'mongoose';
2
- import { applyWorkflowPlugin } from "../shared/workflow.plugin";
3
- import { SortCode } from '../value-objects/sort-code';
4
- import { AccountNumber } from "../value-objects/account-number";
5
- import { applyAuditMiddleware } from "@dynamatix/cat-shared/middlewares";
6
- const applicationDirectDebitSchema = new mongoose.Schema({
7
- applicationId: {
8
- type: mongoose.Schema.Types.ObjectId,
9
- ref: 'Application',
10
- description: 'Reference to the application this direct debit belongs to',
11
- },
12
- pageValidFlag: { type: Boolean, default: false },
13
- primaryApplicantId: {
14
- type: mongoose.Schema.Types.ObjectId,
15
- ref: 'Applicant',
16
- description: 'Reference to the primary applicant',
17
- },
18
- accountNumber: {
19
- type: AccountNumber,
20
- isRequired: true,
21
- maxLength: 8,
22
- description: 'Bank account number of the applicant',
23
- },
24
- addressLine1: {
25
- type: String,
26
- description: 'First line of the applicant’s address'
27
- },
28
- addressLine2: {
29
- type: String,
30
- description: 'Second line of the applicant’s address'
31
- },
32
- applicantId: {
33
- type: mongoose.Schema.Types.ObjectId,
34
- ref: 'Applicant',
35
- description: 'List of applicant IDs associated with this direct debit',
36
- },
37
- branch: {
38
- type: String,
39
- description: 'Branch name or code of the bank',
40
- required: true
41
- },
42
- city: {
43
- type: String,
44
- description: 'City of the applicant’s address',
45
- },
46
- contactPostcode: {
47
- type: String,
48
- description: 'Postcode for correspondence',
49
- requird: true
50
- },
51
- institution: {
52
- type: String,
53
- description: 'Name of the financial institution',
54
- required: true,
55
- },
56
- isConfirmDeclaration: {
57
- type: Boolean,
58
- description: 'Whether the applicant has confirmed the declaration'
59
- },
60
- nameOfAccountHolder: {
61
- type: String,
62
- description: 'Full name of the bank account holder',
63
- required: true,
64
- },
65
- selectedPaymentDayLid: {
66
- type: mongoose.Schema.Types.ObjectId,
67
- ref: 'Lookup',
68
- description: 'Lookup reference for selected payment day',
69
- },
70
- sortCode: {
71
- type: SortCode,
72
- description: 'UK bank sort code in XX-XX-XX format',
73
- required: true,
74
- },
75
- accountErrorLid: {
76
- type: mongoose.Schema.Types.ObjectId,
77
- ref: 'Lookup',
78
- default: null,
79
- description: 'Lookup reference for account error status for algbra',
80
- },
81
- accountStatusLid: {
82
- type: mongoose.Schema.Types.ObjectId,
83
- ref: 'Lookup',
84
- default: null,
85
- description: 'Lookup reference for account status for algbra',
86
- },
87
- bankAccountRequired: {
88
- type: Boolean,
89
- default: false,
90
- },
91
- accountErrorMessage: {
92
- type: String,
93
- default: "",
94
- description: 'Error message for the account error for algbra',
95
- },
96
- bankWizardCheck: {
97
- nameAndDobMatch: { type: String },
98
- addressMatch: { type: String },
99
- ddCapable: { type: String },
100
- validation: { type: String },
101
- status: { type: String },
102
- failedMessage: { type: String },
103
- overrideReason: { type: String, default: "" },
104
- nameAddressOverride: {
105
- firstName: { type: String },
106
- middleName: { type: String },
107
- lastName: { type: String },
108
- buildingName: { type: String },
109
- buildingNumber: { type: String },
110
- street: { type: String },
111
- addressLine2: { type: String },
112
- city: { type: String },
113
- country: { type: String },
114
- postcode: { type: String }
115
- }
116
- },
117
- }, {
118
- timestamps: true,
119
- toJSON: { virtuals: true, getters: true },
120
- toObject: { virtuals: true, getters: true }
121
- });
122
- const virtualselectedPaymentDay = applicationDirectDebitSchema.virtual('selectedPaymentDay', {
123
- ref: 'Lookup',
124
- localField: 'selectedPaymentDayLid',
125
- foreignField: '_id',
126
- justOne: true,
127
- options: {
128
- select: 'label' // Only fetch the 'label' field from the Lookup collection
129
- }
130
- });
131
- virtualselectedPaymentDay.description = 'Populated lookup value for the selected payment day';
132
- const virtualApplicants = applicationDirectDebitSchema.virtual('applicants', {
133
- ref: 'Applicant',
134
- localField: 'applicantId',
135
- foreignField: '_id',
136
- justOne: true,
137
- options: {
138
- select: 'fullName'
139
- }
140
- });
141
- virtualApplicants.description = 'Full Name of the applicant';
142
- // Index for applicationId queries
143
- applicationDirectDebitSchema.index({ applicationId: 1 });
144
- applyAuditMiddleware(applicationDirectDebitSchema, "application_directdebit");
145
- // Apply workflow plugin to the schema
146
- applyWorkflowPlugin(applicationDirectDebitSchema, 'application_directdebit');
147
- const ApplicationDirectDebitModel = mongoose.model("Application_DirectDebit", applicationDirectDebitSchema);
148
- export default ApplicationDirectDebitModel;
1
+ import mongoose from 'mongoose';
2
+ import { applyWorkflowPlugin } from "../shared/workflow.plugin";
3
+ import { SortCode } from '../value-objects/sort-code';
4
+ import { AccountNumber } from "../value-objects/account-number";
5
+ import { applyAuditMiddleware } from "@dynamatix/cat-shared/middlewares";
6
+ const applicationDirectDebitSchema = new mongoose.Schema({
7
+ applicationId: {
8
+ type: mongoose.Schema.Types.ObjectId,
9
+ ref: 'Application',
10
+ description: 'Reference to the application this direct debit belongs to',
11
+ },
12
+ pageValidFlag: { type: Boolean, default: false },
13
+ primaryApplicantId: {
14
+ type: mongoose.Schema.Types.ObjectId,
15
+ ref: 'Applicant',
16
+ description: 'Reference to the primary applicant',
17
+ },
18
+ accountNumber: {
19
+ type: AccountNumber,
20
+ isRequired: true,
21
+ maxLength: 8,
22
+ description: 'Bank account number of the applicant',
23
+ },
24
+ addressLine1: {
25
+ type: String,
26
+ description: 'First line of the applicant’s address'
27
+ },
28
+ addressLine2: {
29
+ type: String,
30
+ description: 'Second line of the applicant’s address'
31
+ },
32
+ applicantId: {
33
+ type: mongoose.Schema.Types.ObjectId,
34
+ ref: 'Applicant',
35
+ description: 'List of applicant IDs associated with this direct debit',
36
+ },
37
+ previousSelectedApplicantId: {
38
+ type: mongoose.Schema.Types.ObjectId,
39
+ ref: 'Applicant',
40
+ description: 'Previously selected applicant before the latest change',
41
+ },
42
+ branch: {
43
+ type: String,
44
+ description: 'Branch name or code of the bank',
45
+ required: true
46
+ },
47
+ city: {
48
+ type: String,
49
+ description: 'City of the applicant’s address',
50
+ },
51
+ contactPostcode: {
52
+ type: String,
53
+ description: 'Postcode for correspondence',
54
+ requird: true
55
+ },
56
+ institution: {
57
+ type: String,
58
+ description: 'Name of the financial institution',
59
+ required: true,
60
+ },
61
+ isConfirmDeclaration: {
62
+ type: Boolean,
63
+ description: 'Whether the applicant has confirmed the declaration'
64
+ },
65
+ nameOfAccountHolder: {
66
+ type: String,
67
+ description: 'Full name of the bank account holder',
68
+ required: true,
69
+ },
70
+ selectedPaymentDayLid: {
71
+ type: mongoose.Schema.Types.ObjectId,
72
+ ref: 'Lookup',
73
+ description: 'Lookup reference for selected payment day',
74
+ },
75
+ sortCode: {
76
+ type: SortCode,
77
+ description: 'UK bank sort code in XX-XX-XX format',
78
+ required: true,
79
+ },
80
+ accountErrorLid: {
81
+ type: mongoose.Schema.Types.ObjectId,
82
+ ref: 'Lookup',
83
+ default: null,
84
+ description: 'Lookup reference for account error status for algbra',
85
+ },
86
+ accountStatusLid: {
87
+ type: mongoose.Schema.Types.ObjectId,
88
+ ref: 'Lookup',
89
+ default: null,
90
+ description: 'Lookup reference for account status for algbra',
91
+ },
92
+ bankAccountRequired: {
93
+ type: Boolean,
94
+ default: false,
95
+ },
96
+ accountErrorMessage: {
97
+ type: String,
98
+ default: "",
99
+ description: 'Error message for the account error for algbra',
100
+ },
101
+ bankWizardCheck: {
102
+ nameAndDobMatch: { type: String },
103
+ addressMatch: { type: String },
104
+ ddCapable: { type: String },
105
+ validation: { type: String },
106
+ status: { type: String },
107
+ failedMessage: { type: String },
108
+ overrideReason: { type: String, default: "" },
109
+ nameAddressOverride: {
110
+ firstName: { type: String },
111
+ middleName: { type: String },
112
+ lastName: { type: String },
113
+ buildingName: { type: String },
114
+ buildingNumber: { type: String },
115
+ street: { type: String },
116
+ addressLine2: { type: String },
117
+ city: { type: String },
118
+ county: { type: String },
119
+ postcode: { type: String },
120
+ isInitialSearchCompleted: { type: Boolean, default: false },
121
+ isNameAddressOverridden: { type: Boolean, default: false }
122
+ }
123
+ },
124
+ }, {
125
+ timestamps: true,
126
+ toJSON: { virtuals: true, getters: true },
127
+ toObject: { virtuals: true, getters: true }
128
+ });
129
+ const virtualselectedPaymentDay = applicationDirectDebitSchema.virtual('selectedPaymentDay', {
130
+ ref: 'Lookup',
131
+ localField: 'selectedPaymentDayLid',
132
+ foreignField: '_id',
133
+ justOne: true,
134
+ options: {
135
+ select: 'label' // Only fetch the 'label' field from the Lookup collection
136
+ }
137
+ });
138
+ virtualselectedPaymentDay.description = 'Populated lookup value for the selected payment day';
139
+ const virtualApplicants = applicationDirectDebitSchema.virtual('applicants', {
140
+ ref: 'Applicant',
141
+ localField: 'applicantId',
142
+ foreignField: '_id',
143
+ justOne: true,
144
+ options: {
145
+ select: 'fullName'
146
+ }
147
+ });
148
+ virtualApplicants.description = 'Full Name of the applicant';
149
+ // Index for applicationId queries
150
+ applicationDirectDebitSchema.index({ applicationId: 1 });
151
+ applyAuditMiddleware(applicationDirectDebitSchema, "application_directdebit");
152
+ // Apply workflow plugin to the schema
153
+ applyWorkflowPlugin(applicationDirectDebitSchema, 'application_directdebit');
154
+ const ApplicationDirectDebitModel = mongoose.model("Application_DirectDebit", applicationDirectDebitSchema);
155
+ export default ApplicationDirectDebitModel;
@@ -1,238 +1,246 @@
1
- import mongoose from "mongoose";
2
- import { applyAuditMiddleware } from "@dynamatix/cat-shared/middlewares";
3
- import creditProfileSchema from "./application-credit-profile.model";
4
- import { applyWorkflowPlugin } from "../shared/workflow.plugin";
5
- const applicationSchema = new mongoose.Schema({
6
- queueId: [{
7
- type: mongoose.Schema.Types.ObjectId,
8
- ref: "Queue",
9
- default: null,
10
- }],
11
- underwriterReviewDate: { type: Date, default: null },
12
- assignedToUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
13
- assignedToUserDate: { type: Date, default: null },
14
- firstAssignedToUserDate: { type: Date, default: null },
15
- slaClockStart: { type: Date, default: null },
16
- slaClockStop: { type: Date, default: null },
17
- applicationId: { type: String, required: true },
18
- isApplicationFeePaid: { type: String, required: true },
19
- applicationNumber: { type: String, required: true },
20
- applicationTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
21
- bankSolicitor: { type: String, default: "" },
22
- brokerId: { type: mongoose.Schema.Types.ObjectId, ref: "Broker", default: null },
23
- caseManager: { type: String, default: "" },
24
- caseManagerAccepted: { type: String, default: false },
25
- completedReason: { type: String, default: "" },
26
- isIntendToOccupy: { type: String, required: true },
27
- introducer: { type: String, default: "" },
28
- isIntroducerSubmission: { type: String, required: true },
29
- isBrokerAssigned: { type: String, default: false },
30
- isFinanceRecommendedToApplicant: { type: String, required: true },
31
- isWorkflowTaskCreated: { type: String, required: true },
32
- lastUpdated: { type: String },
33
- lendingTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
34
- networkClubName: { type: String, default: "" },
35
- isNetworkClubSubmission: { type: String, required: true },
36
- newReason: { type: String, default: "" },
37
- purchaseTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
38
- rejectedReason: { type: String, default: "" },
39
- repaymentTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
40
- selectedProduct: { type: String, required: false },
41
- statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
42
- submitReason: { type: String, default: "" },
43
- submittedDate: { type: String },
44
- underwriter: { type: String, default: "" },
45
- isValuationFeePaid: { type: String, required: true },
46
- withdrawalReasonLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
47
- declineReasonLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
48
- isPortfolioConfirmed: { type: Boolean, default: false },
49
- productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product", default: null },
50
- product: { type: String },
51
- securityId: { type: mongoose.Schema.Types.ObjectId, ref: "Security", default: null },
52
- solicitorId: { type: mongoose.Schema.Types.ObjectId, ref: "Solicitor", default: null },
53
- riskNarrativeId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationRiskNarrative", default: null },
54
- applicants: [
55
- { type: mongoose.Schema.Types.ObjectId, ref: "Applicant", default: null }
56
- ],
57
- isActive: { type: String, default: false },
58
- riskRating: { type: String },
59
- directDebitId: { type: mongoose.Schema.Types.ObjectId, ref: "Application_DirectDebit", default: null },
60
- creditProfile: creditProfileSchema,
61
- mortgageId: { type: mongoose.Schema.Types.ObjectId, ref: "Mortgage", default: null },
62
- companyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationCompany", default: null },
63
- offerId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationOffer", default: null },
64
- newAuditRecordsCount: { type: Number, default: 0 }, // Ensure it is a Number
65
- currentApprivoAuditId: Number,
66
- propertyIds: [{ type: mongoose.Schema.Types.ObjectId, ref: "Property" }],
67
- valuationId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationValuation" },
68
- valuationReportId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationValuationReport" },
69
- isMandateRequested: { type: Boolean, default: false },
70
- isMandateApproved: { type: Boolean, default: null },
71
- mandateReviewComments: { type: String, default: "" },
72
- mandateRequestedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
73
- mandateRequestedDate: { type: Date, default: null },
74
- mandateReviewedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
75
- mandateReviewedDate: { type: Date, default: null },
76
- isReferred: { type: Boolean, default: false },
77
- referredByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
78
- referredDate: { type: Date, default: null },
79
- referralClearedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
80
- referralClearedDate: { type: Date, default: null },
81
- brokerTaskCount: {
82
- type: Number,
83
- default: 0
84
- },
85
- lenderTaskCount: {
86
- type: Number,
87
- default: 0
88
- },
89
- pendingTaskCountForUser: {
90
- type: Number,
91
- default: 0
92
- },
93
- applicationFormSignedDate: {
94
- type: Date, // Stores as ISODate in MongoDB (e.g., "2023-11-15T12:30:45.123Z")
95
- default: null
96
- },
97
- isUkResident: {
98
- type: Boolean,
99
- default: false
100
- },
101
- creditReportId: { type: String, default: null },
102
- isAlgbraEligible: { type: Boolean, default: false },
103
- }, {
104
- timestamps: true,
105
- toJSON: { virtuals: true },
106
- toObject: { virtuals: true }
107
- });
108
- applyAuditMiddleware(applicationSchema, "Application");
109
- // Apply workflow plugin to the schema
110
- applyWorkflowPlugin(applicationSchema, 'application');
111
- // Virtual property 'noOfApplicants'
112
- applicationSchema.virtual('noOfApplicants').get(function () {
113
- return this.applicants ? this.applicants.length : 0;
114
- });
115
- // Virtual property 'applicationTypeName'
116
- applicationSchema.virtual('applicationTypeName').get(function () {
117
- return this.applicationTypeLid instanceof mongoose.Types.ObjectId
118
- ? null
119
- : this.applicationTypeLid?.name ?? null;
120
- });
121
- // Virtual property 'lendingType'
122
- applicationSchema.virtual('lendingType').get(function () {
123
- return this.lendingTypeLid instanceof mongoose.Types.ObjectId
124
- ? null
125
- : this.lendingTypeLid?.name ?? null;
126
- });
127
- // Virtual property 'purchaseType'
128
- applicationSchema.virtual('purchaseType').get(function () {
129
- return this.purchaseTypeLid instanceof mongoose.Types.ObjectId
130
- ? null
131
- : this.purchaseTypeLid?.text ?? null;
132
- });
133
- // Virtual property 'status'
134
- applicationSchema.virtual('status').get(function () {
135
- return this.statusLid instanceof mongoose.Types.ObjectId ? null : this.statusLid?.name ?? null;
136
- });
137
- // Ensure the fields are populated when querying
138
- applicationSchema.pre('find', function () {
139
- this.populate('applicationTypeLid').populate('lendingTypeLid').populate('statusLid');
140
- });
141
- applicationSchema.pre('findOne', function () {
142
- this.populate('applicationTypeLid').populate('lendingTypeLid').populate('statusLid');
143
- });
144
- // Virtual property 'LTV %'
145
- applicationSchema.virtual('ltv').get(function () {
146
- const purchasePrice = this.mortgageId?.purchasePrice;
147
- const loanRequired = this.mortgageId?.loanRequired;
148
- if (purchasePrice && loanRequired) {
149
- const parseCurrency = (value) => {
150
- if (typeof value === 'string') {
151
- return parseFloat(value.replace(/[^0-9.-]+/g, ""));
152
- }
153
- return value;
154
- };
155
- const parsedPurchasePrice = parseCurrency(purchasePrice);
156
- const parsedLoanRequired = parseCurrency(loanRequired);
157
- const ltv = (parsedLoanRequired / parsedPurchasePrice) * 100;
158
- return ltv.toFixed(2) + "%";
159
- }
160
- return null;
161
- });
162
- applicationSchema.virtual('submittedDateFormatted').get(function () {
163
- if (!this.submittedDate)
164
- return null;
165
- const date = new Date(this.submittedDate);
166
- const day = String(date.getDate()).padStart(2, '0');
167
- const month = String(date.getMonth() + 1).padStart(2, '0');
168
- const year = date.getFullYear();
169
- return `${day}-${month}-${year}`;
170
- });
171
- // Virtual property for broker name
172
- applicationSchema.virtual('brokerName').get(function () {
173
- if (this.brokerId && typeof this.brokerId === 'object' && this.brokerId.firstName && this.brokerId.lastName) {
174
- return this.brokerId.firstName + " " + this.brokerId.lastName;
175
- }
176
- return null;
177
- });
178
- applicationSchema.virtual('brokerEmail').get(function () {
179
- return this.brokerId && typeof this.brokerId === 'object' ? this.brokerId.email : null;
180
- });
181
- applicationSchema.virtual('solicitorName').get(function () {
182
- return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.nameOfAccountHolder : null;
183
- });
184
- applicationSchema.virtual('solicitorEmail').get(function () {
185
- return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.email : null;
186
- });
187
- applicationSchema.virtual('brokerPhone').get(function () {
188
- return this.brokerId && typeof this.brokerId === 'object' ? this.brokerId.mobileTelephone : null;
189
- });
190
- applicationSchema.virtual('solicitorPhone').get(function () {
191
- return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.telephone : null;
192
- });
193
- // Virtual property 'pendingDays'
194
- applicationSchema.virtual('pendingDays').get(function () {
195
- if (!this.applicationFormSignedDate)
196
- return null;
197
- // Get current date at midnight (ignoring time)
198
- const now = new Date();
199
- const todayMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
200
- // Get signed date at midnight (ignoring time)
201
- const signedDate = new Date(this.applicationFormSignedDate);
202
- const signedMidnight = new Date(signedDate.getFullYear(), signedDate.getMonth(), signedDate.getDate());
203
- // Calculate difference in just date
204
- const diffTime = todayMidnight.getTime() - signedMidnight.getTime();
205
- // Convert to days
206
- const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
207
- return diffDays;
208
- });
209
- // Virtual property 'taskCompletionPercent'
210
- applicationSchema.virtual('taskCompletionPercent').get(function () {
211
- const broker = typeof this.brokerTaskCount === 'number' ? this.brokerTaskCount : 0;
212
- const lender = typeof this.lenderTaskCount === 'number' ? this.lenderTaskCount : 0;
213
- const total = broker + lender;
214
- // If both broker and lender are 0, return 100.00
215
- if (broker === 0 && lender === 0)
216
- return 100.00;
217
- // If broker is 0 and lender is not, return 100.00
218
- if (broker === 0 && lender > 0)
219
- return 100.00;
220
- // If lender is 0 and broker is not, return 0.00
221
- if (lender === 0 && broker > 0)
222
- return 0.00;
223
- // Calculate (lender/total)*100
224
- return Number(((lender / total) * 100).toFixed(2));
225
- });
226
- // Database indexes for performance optimization
227
- // Single field indexes
228
- applicationSchema.index({ applicationId: 1 });
229
- applicationSchema.index({ assignedToUserId: 1 });
230
- applicationSchema.index({ brokerId: 1 });
231
- applicationSchema.index({ applicants: 1 }); // For array membership queries
232
- // Compound indexes for common query combinations
233
- applicationSchema.index({ applicants: 1, _id: 1 }); // For finding application by applicant
234
- applicationSchema.index({ assignedToUserId: 1, statusLid: 1 }); // For filtering by assignee and status
235
- // Text index for search functionality
236
- applicationSchema.index({ applicationNumber: "text" });
237
- const ApplicationModel = mongoose.model("Application", applicationSchema);
238
- export default ApplicationModel;
1
+ import mongoose from "mongoose";
2
+ import { applyAuditMiddleware } from "@dynamatix/cat-shared/middlewares";
3
+ import creditProfileSchema from "./application-credit-profile.model";
4
+ import { applyWorkflowPlugin } from "../shared/workflow.plugin";
5
+ const applicationSchema = new mongoose.Schema({
6
+ queueId: [{
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: "Queue",
9
+ default: null,
10
+ }],
11
+ underwriterReviewDate: { type: Date, default: null },
12
+ assignedToUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
13
+ assignedToUserDate: { type: Date, default: null },
14
+ firstAssignedToUserDate: { type: Date, default: null },
15
+ slaClockStart: { type: Date, default: null },
16
+ slaClockStop: { type: Date, default: null },
17
+ applicationId: { type: String, required: true },
18
+ isApplicationFeePaid: { type: String, required: true },
19
+ applicationNumber: { type: String, required: true },
20
+ applicationTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
21
+ bankSolicitor: { type: String, default: "" },
22
+ brokerId: { type: mongoose.Schema.Types.ObjectId, ref: "Broker", default: null },
23
+ caseManager: { type: String, default: "" },
24
+ caseManagerAccepted: { type: String, default: false },
25
+ completedReason: { type: String, default: "" },
26
+ isIntendToOccupy: { type: String, required: true },
27
+ introducer: { type: String, default: "" },
28
+ isIntroducerSubmission: { type: String, required: true },
29
+ isBrokerAssigned: { type: String, default: false },
30
+ isFinanceRecommendedToApplicant: { type: String, required: true },
31
+ isWorkflowTaskCreated: { type: String, required: true },
32
+ lastUpdated: { type: String },
33
+ lendingTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
34
+ networkClubName: { type: String, default: "" },
35
+ isNetworkClubSubmission: { type: String, required: true },
36
+ newReason: { type: String, default: "" },
37
+ purchaseTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
38
+ rejectedReason: { type: String, default: "" },
39
+ repaymentTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
40
+ selectedProduct: { type: String, required: false },
41
+ statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
42
+ submitReason: { type: String, default: "" },
43
+ submittedDate: { type: String },
44
+ underwriter: { type: String, default: "" },
45
+ isValuationFeePaid: { type: String, required: true },
46
+ withdrawalReasonLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
47
+ declineReasonLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
48
+ isPortfolioConfirmed: { type: Boolean, default: false },
49
+ productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product", default: null },
50
+ product: { type: String },
51
+ securityId: { type: mongoose.Schema.Types.ObjectId, ref: "Security", default: null },
52
+ solicitorId: { type: mongoose.Schema.Types.ObjectId, ref: "Solicitor", default: null },
53
+ riskNarrativeId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationRiskNarrative", default: null },
54
+ riskNarrative: {
55
+ call1RequestedOn: { type: String, default: null },
56
+ call2RequestedOn: { type: String, default: null },
57
+ retryCount: { type: String, default: null },
58
+ riskRating: { type: String, default: null },
59
+ statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
60
+ call2StatusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
61
+ },
62
+ applicants: [
63
+ { type: mongoose.Schema.Types.ObjectId, ref: "Applicant", default: null }
64
+ ],
65
+ isActive: { type: String, default: false },
66
+ riskRating: { type: String },
67
+ directDebitId: { type: mongoose.Schema.Types.ObjectId, ref: "Application_DirectDebit", default: null },
68
+ creditProfile: creditProfileSchema,
69
+ mortgageId: { type: mongoose.Schema.Types.ObjectId, ref: "Mortgage", default: null },
70
+ companyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationCompany", default: null },
71
+ offerId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationOffer", default: null },
72
+ newAuditRecordsCount: { type: Number, default: 0 }, // Ensure it is a Number
73
+ currentApprivoAuditId: Number,
74
+ propertyIds: [{ type: mongoose.Schema.Types.ObjectId, ref: "Property" }],
75
+ valuationId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationValuation" },
76
+ valuationReportId: { type: mongoose.Schema.Types.ObjectId, ref: "ApplicationValuationReport" },
77
+ isMandateRequested: { type: Boolean, default: false },
78
+ isMandateApproved: { type: Boolean, default: null },
79
+ mandateReviewComments: { type: String, default: "" },
80
+ mandateRequestedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
81
+ mandateRequestedDate: { type: Date, default: null },
82
+ mandateReviewedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
83
+ mandateReviewedDate: { type: Date, default: null },
84
+ isReferred: { type: Boolean, default: false },
85
+ referredByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
86
+ referredDate: { type: Date, default: null },
87
+ referralClearedByUserId: { type: mongoose.Schema.Types.ObjectId, ref: "User", default: null },
88
+ referralClearedDate: { type: Date, default: null },
89
+ brokerTaskCount: {
90
+ type: Number,
91
+ default: 0
92
+ },
93
+ lenderTaskCount: {
94
+ type: Number,
95
+ default: 0
96
+ },
97
+ pendingTaskCountForUser: {
98
+ type: Number,
99
+ default: 0
100
+ },
101
+ applicationFormSignedDate: {
102
+ type: Date, // Stores as ISODate in MongoDB (e.g., "2023-11-15T12:30:45.123Z")
103
+ default: null
104
+ },
105
+ isUkResident: {
106
+ type: Boolean,
107
+ default: false
108
+ },
109
+ creditReportId: { type: String, default: null },
110
+ isAlgbraEligible: { type: Boolean, default: false },
111
+ }, {
112
+ timestamps: true,
113
+ toJSON: { virtuals: true },
114
+ toObject: { virtuals: true }
115
+ });
116
+ applyAuditMiddleware(applicationSchema, "Application");
117
+ // Apply workflow plugin to the schema
118
+ applyWorkflowPlugin(applicationSchema, 'application');
119
+ // Virtual property 'noOfApplicants'
120
+ applicationSchema.virtual('noOfApplicants').get(function () {
121
+ return this.applicants ? this.applicants.length : 0;
122
+ });
123
+ // Virtual property 'applicationTypeName'
124
+ applicationSchema.virtual('applicationTypeName').get(function () {
125
+ return this.applicationTypeLid instanceof mongoose.Types.ObjectId
126
+ ? null
127
+ : this.applicationTypeLid?.name ?? null;
128
+ });
129
+ // Virtual property 'lendingType'
130
+ applicationSchema.virtual('lendingType').get(function () {
131
+ return this.lendingTypeLid instanceof mongoose.Types.ObjectId
132
+ ? null
133
+ : this.lendingTypeLid?.name ?? null;
134
+ });
135
+ // Virtual property 'purchaseType'
136
+ applicationSchema.virtual('purchaseType').get(function () {
137
+ return this.purchaseTypeLid instanceof mongoose.Types.ObjectId
138
+ ? null
139
+ : this.purchaseTypeLid?.text ?? null;
140
+ });
141
+ // Virtual property 'status'
142
+ applicationSchema.virtual('status').get(function () {
143
+ return this.statusLid instanceof mongoose.Types.ObjectId ? null : this.statusLid?.name ?? null;
144
+ });
145
+ // Ensure the fields are populated when querying
146
+ applicationSchema.pre('find', function () {
147
+ this.populate('applicationTypeLid').populate('lendingTypeLid').populate('statusLid');
148
+ });
149
+ applicationSchema.pre('findOne', function () {
150
+ this.populate('applicationTypeLid').populate('lendingTypeLid').populate('statusLid');
151
+ });
152
+ // Virtual property 'LTV %'
153
+ applicationSchema.virtual('ltv').get(function () {
154
+ const purchasePrice = this.mortgageId?.purchasePrice;
155
+ const loanRequired = this.mortgageId?.loanRequired;
156
+ if (purchasePrice && loanRequired) {
157
+ const parseCurrency = (value) => {
158
+ if (typeof value === 'string') {
159
+ return parseFloat(value.replace(/[^0-9.-]+/g, ""));
160
+ }
161
+ return value;
162
+ };
163
+ const parsedPurchasePrice = parseCurrency(purchasePrice);
164
+ const parsedLoanRequired = parseCurrency(loanRequired);
165
+ const ltv = (parsedLoanRequired / parsedPurchasePrice) * 100;
166
+ return ltv.toFixed(2) + "%";
167
+ }
168
+ return null;
169
+ });
170
+ applicationSchema.virtual('submittedDateFormatted').get(function () {
171
+ if (!this.submittedDate)
172
+ return null;
173
+ const date = new Date(this.submittedDate);
174
+ const day = String(date.getDate()).padStart(2, '0');
175
+ const month = String(date.getMonth() + 1).padStart(2, '0');
176
+ const year = date.getFullYear();
177
+ return `${day}-${month}-${year}`;
178
+ });
179
+ // Virtual property for broker name
180
+ applicationSchema.virtual('brokerName').get(function () {
181
+ if (this.brokerId && typeof this.brokerId === 'object' && this.brokerId.firstName && this.brokerId.lastName) {
182
+ return this.brokerId.firstName + " " + this.brokerId.lastName;
183
+ }
184
+ return null;
185
+ });
186
+ applicationSchema.virtual('brokerEmail').get(function () {
187
+ return this.brokerId && typeof this.brokerId === 'object' ? this.brokerId.email : null;
188
+ });
189
+ applicationSchema.virtual('solicitorName').get(function () {
190
+ return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.nameOfAccountHolder : null;
191
+ });
192
+ applicationSchema.virtual('solicitorEmail').get(function () {
193
+ return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.email : null;
194
+ });
195
+ applicationSchema.virtual('brokerPhone').get(function () {
196
+ return this.brokerId && typeof this.brokerId === 'object' ? this.brokerId.mobileTelephone : null;
197
+ });
198
+ applicationSchema.virtual('solicitorPhone').get(function () {
199
+ return this.solicitorId && typeof this.solicitorId === 'object' ? this.solicitorId.telephone : null;
200
+ });
201
+ // Virtual property 'pendingDays'
202
+ applicationSchema.virtual('pendingDays').get(function () {
203
+ if (!this.applicationFormSignedDate)
204
+ return null;
205
+ // Get current date at midnight (ignoring time)
206
+ const now = new Date();
207
+ const todayMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
208
+ // Get signed date at midnight (ignoring time)
209
+ const signedDate = new Date(this.applicationFormSignedDate);
210
+ const signedMidnight = new Date(signedDate.getFullYear(), signedDate.getMonth(), signedDate.getDate());
211
+ // Calculate difference in just date
212
+ const diffTime = todayMidnight.getTime() - signedMidnight.getTime();
213
+ // Convert to days
214
+ const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
215
+ return diffDays;
216
+ });
217
+ // Virtual property 'taskCompletionPercent'
218
+ applicationSchema.virtual('taskCompletionPercent').get(function () {
219
+ const broker = typeof this.brokerTaskCount === 'number' ? this.brokerTaskCount : 0;
220
+ const lender = typeof this.lenderTaskCount === 'number' ? this.lenderTaskCount : 0;
221
+ const total = broker + lender;
222
+ // If both broker and lender are 0, return 100.00
223
+ if (broker === 0 && lender === 0)
224
+ return 100.00;
225
+ // If broker is 0 and lender is not, return 100.00
226
+ if (broker === 0 && lender > 0)
227
+ return 100.00;
228
+ // If lender is 0 and broker is not, return 0.00
229
+ if (lender === 0 && broker > 0)
230
+ return 0.00;
231
+ // Calculate (lender/total)*100
232
+ return Number(((lender / total) * 100).toFixed(2));
233
+ });
234
+ // Database indexes for performance optimization
235
+ // Single field indexes
236
+ applicationSchema.index({ applicationId: 1 });
237
+ applicationSchema.index({ assignedToUserId: 1 });
238
+ applicationSchema.index({ brokerId: 1 });
239
+ applicationSchema.index({ applicants: 1 }); // For array membership queries
240
+ // Compound indexes for common query combinations
241
+ applicationSchema.index({ applicants: 1, _id: 1 }); // For finding application by applicant
242
+ applicationSchema.index({ assignedToUserId: 1, statusLid: 1 }); // For filtering by assignee and status
243
+ // Text index for search functionality
244
+ applicationSchema.index({ applicationNumber: "text" });
245
+ const ApplicationModel = mongoose.model("Application", applicationSchema);
246
+ export default ApplicationModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "2.3.394",
3
+ "version": "2.3.395",
4
4
  "description": "All the schemas for gatehouse bank back-end",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",