@dynamatix/gb-schemas 2.3.261 → 2.3.262
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicant-welcome-call.model.d.ts","sourceRoot":"","sources":["../../applicants/applicant-welcome-call.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"applicant-welcome-call.model.d.ts","sourceRoot":"","sources":["../../applicants/applicant-welcome-call.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAoiBhC,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA4D,CAAC;AAEnF,eAAe,gBAAgB,CAAC"}
|
|
@@ -226,12 +226,18 @@ welcomeCallSchema.virtual('customerCurrentResidentialAddress').get(function () {
|
|
|
226
226
|
const applicant = this.applicantId;
|
|
227
227
|
// Use only regular address fields (addressLine1, addressLine2, addressLine3)
|
|
228
228
|
if (applicant.addressLine1) {
|
|
229
|
+
// Get country name from populated addressCountryLid
|
|
230
|
+
let countryName = '';
|
|
231
|
+
if (applicant.addressCountryLid && typeof applicant.addressCountryLid === 'object') {
|
|
232
|
+
countryName = applicant.addressCountryLid.name || '';
|
|
233
|
+
}
|
|
229
234
|
const addressParts = [
|
|
230
235
|
applicant.addressLine1,
|
|
231
236
|
applicant.addressLine2,
|
|
232
237
|
applicant.addressLine3,
|
|
233
238
|
applicant.addressCity,
|
|
234
|
-
applicant.addressPostCode
|
|
239
|
+
applicant.addressPostCode,
|
|
240
|
+
countryName
|
|
235
241
|
].filter(part => part && part.trim() !== '');
|
|
236
242
|
return addressParts.join(', ');
|
|
237
243
|
}
|
|
@@ -257,46 +263,101 @@ welcomeCallSchema.virtual('customerContactNumbers').get(function () {
|
|
|
257
263
|
});
|
|
258
264
|
// Virtual property for all applicants name/DOB when there are multiple applicants
|
|
259
265
|
welcomeCallSchema.virtual('allApplicantsNameAndDOB').get(function () {
|
|
260
|
-
//
|
|
261
|
-
if (this.
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
// Get application and its applicants
|
|
267
|
+
if (this.applicationId && typeof this.applicationId === 'object') {
|
|
268
|
+
const application = this.applicationId;
|
|
269
|
+
// Get all applicants from the application (field name is 'applicants')
|
|
270
|
+
if (application.applicants && Array.isArray(application.applicants) && application.applicants.length > 0) {
|
|
271
|
+
// Get current applicant ID for comparison
|
|
272
|
+
const currentApplicantId = this.applicantId?._id || this.applicantId;
|
|
273
|
+
// Filter out the current applicant to get only OTHER applicants
|
|
274
|
+
const otherApplicants = application.applicants.filter((applicant) => {
|
|
275
|
+
const applicantId = applicant._id || applicant;
|
|
276
|
+
return applicantId.toString() !== currentApplicantId.toString();
|
|
277
|
+
});
|
|
278
|
+
// If no other applicants, return "N/A" (single applicant case)
|
|
279
|
+
if (otherApplicants.length === 0) {
|
|
280
|
+
return 'N/A';
|
|
281
|
+
}
|
|
282
|
+
// Format each other applicant as: firstName,middleName,lastName,dd/mm/yyyy
|
|
283
|
+
const formattedApplicants = otherApplicants.map((applicant) => {
|
|
284
|
+
// Check if applicant is an ObjectId (not populated)
|
|
285
|
+
if (typeof applicant === 'string' || (applicant.constructor && applicant.constructor.name === 'ObjectId')) {
|
|
286
|
+
return null; // Skip unpopulated references
|
|
287
|
+
}
|
|
288
|
+
const firstName = applicant.firstName || '';
|
|
289
|
+
const middleName = applicant.middleName || '';
|
|
290
|
+
const lastName = applicant.lastName || '';
|
|
291
|
+
// Combine first and middle names
|
|
292
|
+
const fullFirstName = middleName ? `${firstName},${middleName}` : firstName;
|
|
293
|
+
// Format date of birth to dd/mm/yyyy
|
|
294
|
+
let formattedDOB = '';
|
|
295
|
+
if (applicant.dateOfBirth) {
|
|
296
|
+
// Check if dateOfBirth is already a formatted string (DD/MM/YYYY)
|
|
297
|
+
if (typeof applicant.dateOfBirth === 'string' && /^\d{2}\/\d{2}\/\d{4}$/.test(applicant.dateOfBirth)) {
|
|
298
|
+
// Already in DD/MM/YYYY format
|
|
299
|
+
formattedDOB = applicant.dateOfBirth;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
// Try to parse as Date object or ISO string
|
|
303
|
+
try {
|
|
304
|
+
const date = new Date(applicant.dateOfBirth);
|
|
305
|
+
// Check if date is valid
|
|
306
|
+
if (!isNaN(date.getTime())) {
|
|
307
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
308
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
309
|
+
const year = date.getFullYear();
|
|
310
|
+
formattedDOB = `${day}/${month}/${year}`;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (e) {
|
|
314
|
+
// Date parsing failed, try to use as-is if it's a string
|
|
315
|
+
if (typeof applicant.dateOfBirth === 'string') {
|
|
316
|
+
formattedDOB = applicant.dateOfBirth;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return `${fullFirstName},${lastName},${formattedDOB}`;
|
|
322
|
+
}).filter((line) => line && line.trim() !== ',,' && line.trim() !== '');
|
|
323
|
+
// Join all applicants with newline
|
|
324
|
+
return formattedApplicants.join('\n');
|
|
325
|
+
}
|
|
268
326
|
}
|
|
269
|
-
return
|
|
327
|
+
// If application not populated or no applicants, return "N/A"
|
|
328
|
+
return 'N/A';
|
|
270
329
|
});
|
|
271
330
|
// Virtual property for broker name and firm
|
|
272
331
|
welcomeCallSchema.virtual('brokerNameAndFirm').get(function () {
|
|
273
|
-
|
|
274
|
-
|
|
332
|
+
// Access application from welcome call directly
|
|
333
|
+
if (this.applicationId && typeof this.applicationId === 'object') {
|
|
334
|
+
const application = this.applicationId;
|
|
275
335
|
let brokerName = '';
|
|
276
|
-
let
|
|
277
|
-
// Get broker
|
|
278
|
-
if (application
|
|
336
|
+
let tradingName = '';
|
|
337
|
+
// Get broker information
|
|
338
|
+
if (application.brokerId && typeof application.brokerId === 'object') {
|
|
279
339
|
const broker = application.brokerId;
|
|
340
|
+
// Get broker name
|
|
280
341
|
if (broker.firstName && broker.lastName) {
|
|
281
342
|
brokerName = `${broker.firstName} ${broker.lastName}`;
|
|
282
343
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (
|
|
288
|
-
|
|
344
|
+
// Get trading name (try both lowercase and uppercase)
|
|
345
|
+
if (broker.tradingName) {
|
|
346
|
+
tradingName = broker.tradingName;
|
|
347
|
+
}
|
|
348
|
+
else if (broker.TradingName) {
|
|
349
|
+
tradingName = broker.TradingName;
|
|
289
350
|
}
|
|
290
351
|
}
|
|
291
|
-
// Combine in format "Broker name /
|
|
292
|
-
if (brokerName &&
|
|
293
|
-
return `${brokerName} / ${
|
|
352
|
+
// Combine in format "Broker name / Trading Name"
|
|
353
|
+
if (brokerName && tradingName) {
|
|
354
|
+
return `${brokerName} / ${tradingName}`;
|
|
294
355
|
}
|
|
295
356
|
else if (brokerName) {
|
|
296
357
|
return brokerName;
|
|
297
358
|
}
|
|
298
|
-
else if (
|
|
299
|
-
return
|
|
359
|
+
else if (tradingName) {
|
|
360
|
+
return tradingName;
|
|
300
361
|
}
|
|
301
362
|
}
|
|
302
363
|
return null;
|
|
@@ -332,18 +393,24 @@ welcomeCallSchema.virtual('accountHolderAndBank').get(function () {
|
|
|
332
393
|
});
|
|
333
394
|
// virtual property for property address
|
|
334
395
|
welcomeCallSchema.virtual('customerPropertyAddress').get(function () {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
396
|
+
// Get property address from application's security reference
|
|
397
|
+
if (this.applicationId && typeof this.applicationId === 'object') {
|
|
398
|
+
const application = this.applicationId;
|
|
399
|
+
// Access security details through securityId
|
|
400
|
+
if (application.securityId && typeof application.securityId === 'object') {
|
|
401
|
+
const security = application.securityId;
|
|
402
|
+
// Use property address fields from security model
|
|
403
|
+
if (security.propertyAddressLine1) {
|
|
404
|
+
const addressParts = [
|
|
405
|
+
security.propertyAddressLine1,
|
|
406
|
+
security.propertyAddressLine2,
|
|
407
|
+
security.propertyAddressLine3,
|
|
408
|
+
security.propertyAddressCity,
|
|
409
|
+
security.propertyAddressPostCode
|
|
410
|
+
].filter(part => part && part.trim() !== '')
|
|
411
|
+
.map(part => `${part},`);
|
|
412
|
+
return addressParts.join('\n');
|
|
413
|
+
}
|
|
347
414
|
}
|
|
348
415
|
}
|
|
349
416
|
return null;
|
|
@@ -366,6 +433,70 @@ welcomeCallSchema.virtual('applicantEmployer').get(function () {
|
|
|
366
433
|
}
|
|
367
434
|
return null;
|
|
368
435
|
});
|
|
436
|
+
// Virtual property for product name
|
|
437
|
+
welcomeCallSchema.virtual('productName').get(function () {
|
|
438
|
+
// Get product from application
|
|
439
|
+
if (this.applicationId && typeof this.applicationId === 'object') {
|
|
440
|
+
const application = this.applicationId;
|
|
441
|
+
// First check if selectedProduct is on the application directly
|
|
442
|
+
let selectedProduct = application.selectedProduct;
|
|
443
|
+
// If not found on application, check productId
|
|
444
|
+
if (!selectedProduct || selectedProduct.trim() === '') {
|
|
445
|
+
if (application.productId && typeof application.productId === 'object') {
|
|
446
|
+
selectedProduct = application.productId.selectedProduct;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// Extract text before parentheses if selectedProduct has a value
|
|
450
|
+
if (selectedProduct && typeof selectedProduct === 'string' && selectedProduct.trim() !== '') {
|
|
451
|
+
// Extract text before opening parenthesis and trim whitespace
|
|
452
|
+
const match = selectedProduct.match(/^([^(]+)/);
|
|
453
|
+
if (match && match[1]) {
|
|
454
|
+
let productName = match[1].trim();
|
|
455
|
+
// Remove product type words like "Fixed", "Variable", "Tracker", etc.
|
|
456
|
+
// Split by common product type keywords and return only the first part
|
|
457
|
+
const productTypeKeywords = ['Fixed', 'Variable', 'Tracker', 'Discount', 'Capped'];
|
|
458
|
+
for (const keyword of productTypeKeywords) {
|
|
459
|
+
if (productName.includes(keyword)) {
|
|
460
|
+
productName = productName.split(keyword)[0].trim();
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return productName;
|
|
465
|
+
}
|
|
466
|
+
// If no parentheses found, return the whole string trimmed
|
|
467
|
+
return selectedProduct.trim();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return null;
|
|
471
|
+
});
|
|
472
|
+
// Virtual property for initial rate percentage
|
|
473
|
+
welcomeCallSchema.virtual('initialRatePercentage').get(function () {
|
|
474
|
+
// Get product features from application
|
|
475
|
+
if (this.applicationId && typeof this.applicationId === 'object') {
|
|
476
|
+
const application = this.applicationId;
|
|
477
|
+
// Check if product features are available
|
|
478
|
+
if (application.productFeatures && typeof application.productFeatures === 'object') {
|
|
479
|
+
const productFeatures = application.productFeatures;
|
|
480
|
+
// Get initialRate value
|
|
481
|
+
if (productFeatures.initialRate !== undefined && productFeatures.initialRate !== null) {
|
|
482
|
+
const initialRate = productFeatures.initialRate;
|
|
483
|
+
// Convert to number
|
|
484
|
+
const rateValue = typeof initialRate === 'string' ? parseFloat(initialRate) : initialRate;
|
|
485
|
+
// Check if valid number
|
|
486
|
+
if (!isNaN(rateValue)) {
|
|
487
|
+
// If value is less than 1, it's likely stored as decimal (e.g., 0.0599)
|
|
488
|
+
// Multiply by 100 to get percentage
|
|
489
|
+
// If value is greater than or equal to 1, it's likely already in percentage form (e.g., 5.99)
|
|
490
|
+
// Divide by 100 as requested by user
|
|
491
|
+
const percentageValue = rateValue >= 1 ? rateValue / 100 : rateValue * 100;
|
|
492
|
+
// Format to 2 decimal places and add % sign
|
|
493
|
+
return `${percentageValue.toFixed(2)}%`;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return null;
|
|
499
|
+
});
|
|
369
500
|
// Apply workflow plugin to the schema
|
|
370
501
|
applyWorkflowPlugin(welcomeCallSchema, 'applicantwelcomecall');
|
|
371
502
|
const WelcomeCallModel = mongoose.model('ApplicantWelcomeCall', welcomeCallSchema);
|