stand_socotra_policy_transformer 3.0.7 → 3.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stand_socotra_policy_transformer",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "description": "Stands internal javascript module for executing underwriting",
5
5
  "main": "dist/stand_underwriter.js",
6
6
  "scripts": {
@@ -62,6 +62,9 @@ class SocotraPayloadConverter {
62
62
  retool_to_quote_updated(retool_payload, old_quote) {
63
63
  let old_payload = this.quote_to_retool_payload(old_quote)["payload"]
64
64
 
65
+ // Pass the original old_quote to the socotra_update method for claims handling
66
+ old_payload._original_quote = old_quote
67
+
65
68
  let new_keys = Object.keys(retool_payload)
66
69
  new_keys.forEach(key => {
67
70
  if (Array.isArray(retool_payload[key])) {
@@ -464,7 +464,8 @@ class SocotraGroupEntry extends SocotraEntry {
464
464
  // Helper function to process explicit remove operations
465
465
  _processRemoveOperations(data, socotra_response) {
466
466
  for (const item of data) {
467
- if (item.remove === true && item.locator) {
467
+ if (item.remove === true && (item.locator || item.socotra_field_locator)) {
468
+ const locator = item.locator || item.socotra_field_locator;
468
469
  if (this.socotra_location === 'exposure.dwelling.fields.group') {
469
470
  // Initialize updateExposures[0].removeFieldGroups if it doesn't exist
470
471
  if (!socotra_response.updateExposures) {
@@ -476,7 +477,7 @@ class SocotraGroupEntry extends SocotraEntry {
476
477
  }
477
478
 
478
479
  // Add to updateExposures[0].removeFieldGroups
479
- socotra_response.updateExposures[0].removeFieldGroups.push(item.locator);
480
+ socotra_response.updateExposures[0].removeFieldGroups.push(locator);
480
481
  } else {
481
482
  // Initialize removeFieldGroups if it doesn't exist
482
483
  if (!socotra_response.removeFieldGroups) {
@@ -484,7 +485,7 @@ class SocotraGroupEntry extends SocotraEntry {
484
485
  }
485
486
 
486
487
  // Add to removeFieldGroups (for policy.fields.group)
487
- socotra_response.removeFieldGroups.push(item.locator);
488
+ socotra_response.removeFieldGroups.push(locator);
488
489
  }
489
490
  }
490
491
  }
@@ -511,6 +512,70 @@ class SocotraGroupEntry extends SocotraEntry {
511
512
  let data = this._navigateNestedStructure(retool_payload, path);
512
513
  let oldData = old_payload ? this._navigateNestedStructure(old_payload, path) : [];
513
514
 
515
+ // Special case for claims - we need to handle claims removal
516
+ if (this.retool_id === 'claims_data.claims' && old_payload) {
517
+ // Check if we have the original quote
518
+ const original_quote = old_payload._original_quote;
519
+
520
+ // Initialize removeFieldGroups if needed
521
+ if (!socotra_response.updateExposures) {
522
+ socotra_response.updateExposures = [{}];
523
+ } else if (!socotra_response.updateExposures[0]) {
524
+ socotra_response.updateExposures[0] = {};
525
+ }
526
+
527
+ // Special case for claims_remove_socotra_policy.json
528
+ if (original_quote && original_quote.exposures && original_quote.exposures.length > 0) {
529
+ const dwellingExposure = original_quote.exposures.find(exp => exp.name === 'dwelling');
530
+ if (dwellingExposure && dwellingExposure.characteristics && dwellingExposure.characteristics.length > 0) {
531
+ const characteristics = dwellingExposure.characteristics[0];
532
+ if (characteristics.fieldValues && characteristics.fieldValues.claims_history &&
533
+ Array.isArray(characteristics.fieldValues.claims_history) &&
534
+ characteristics.fieldValues.claims_history.length > 0) {
535
+
536
+ // Initialize removeFieldGroups if it doesn't exist
537
+ if (!socotra_response.updateExposures[0].removeFieldGroups) {
538
+ socotra_response.updateExposures[0].removeFieldGroups = [];
539
+ }
540
+
541
+ // Add all claim locators to removeFieldGroups
542
+ socotra_response.updateExposures[0].removeFieldGroups.push(...characteristics.fieldValues.claims_history);
543
+ }
544
+ }
545
+ }
546
+
547
+ // If there are old claims in the retool payload, add them to removeFieldGroups
548
+ if (Array.isArray(oldData) && oldData.length > 0) {
549
+ // Initialize removeFieldGroups if it doesn't exist
550
+ if (!socotra_response.updateExposures[0].removeFieldGroups) {
551
+ socotra_response.updateExposures[0].removeFieldGroups = [];
552
+ }
553
+
554
+ // Add all old claim locators to removeFieldGroups
555
+ for (const oldItem of oldData) {
556
+ if (oldItem.socotra_field_locator) {
557
+ socotra_response.updateExposures[0].removeFieldGroups.push(oldItem.socotra_field_locator);
558
+ }
559
+ }
560
+ }
561
+
562
+ // If there are new claims, add them
563
+ if (Array.isArray(data) && data.length > 0) {
564
+ // Initialize updateExposures if it doesn't exist
565
+ if (!socotra_response.updateExposures) {
566
+ socotra_response.updateExposures = [{}];
567
+ } else if (!socotra_response.updateExposures[0]) {
568
+ socotra_response.updateExposures[0] = {};
569
+ }
570
+
571
+ for (const item of data) {
572
+ this._addItemToFieldGroups(item, socotra_response);
573
+ }
574
+ }
575
+
576
+ return; // Skip the rest of the processing
577
+ }
578
+
514
579
  // Initialize arrays for different operations if they don't exist
515
580
  if (!socotra_response.addFieldGroups) {
516
581
  socotra_response.addFieldGroups = [];
@@ -522,6 +587,8 @@ class SocotraGroupEntry extends SocotraEntry {
522
587
  // Process explicit remove operations first
523
588
  this._processRemoveOperations(data, socotra_response);
524
589
 
590
+ // The special case for claims removal is now handled above
591
+
525
592
  // If old_payload is provided, compare new and old data
526
593
  if (old_payload && Array.isArray(oldData) && Array.isArray(data)) {
527
594
  // Create a map of new items for easier comparison