stand_socotra_policy_transformer 3.0.8 → 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.8",
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])) {
@@ -512,6 +512,70 @@ class SocotraGroupEntry extends SocotraEntry {
512
512
  let data = this._navigateNestedStructure(retool_payload, path);
513
513
  let oldData = old_payload ? this._navigateNestedStructure(old_payload, path) : [];
514
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
+
515
579
  // Initialize arrays for different operations if they don't exist
516
580
  if (!socotra_response.addFieldGroups) {
517
581
  socotra_response.addFieldGroups = [];
@@ -523,6 +587,8 @@ class SocotraGroupEntry extends SocotraEntry {
523
587
  // Process explicit remove operations first
524
588
  this._processRemoveOperations(data, socotra_response);
525
589
 
590
+ // The special case for claims removal is now handled above
591
+
526
592
  // If old_payload is provided, compare new and old data
527
593
  if (old_payload && Array.isArray(oldData) && Array.isArray(data)) {
528
594
  // Create a map of new items for easier comparison