@ixiam/n8n-nodes-civicrm 1.1.34 → 1.1.35

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.
@@ -750,25 +750,35 @@ class CiviCrm {
750
750
  const val = rawVal;
751
751
  /* Email simple */
752
752
  if (key === 'email') {
753
- emailData.email = val;
753
+ if (val !== '' && val !== null && val !== undefined) {
754
+ emailData.email = val;
755
+ }
754
756
  continue;
755
757
  }
756
758
  if (key.startsWith('email.')) {
757
- emailData[key.replace(/^email\./, '')] = val;
759
+ if (val !== '' && val !== null && val !== undefined) {
760
+ emailData[key.replace(/^email\./, '')] = val;
761
+ }
758
762
  continue;
759
763
  }
760
764
  /* Phone simple */
761
765
  if (key === 'phone') {
762
- phoneData.phone = val;
766
+ if (val !== '' && val !== null && val !== undefined) {
767
+ phoneData.phone = val;
768
+ }
763
769
  continue;
764
770
  }
765
771
  if (key.startsWith('phone.')) {
766
- phoneData[key.replace(/^phone\./, '')] = val;
772
+ if (val !== '' && val !== null && val !== undefined) {
773
+ phoneData[key.replace(/^phone\./, '')] = val;
774
+ }
767
775
  continue;
768
776
  }
769
777
  /* Address */
770
778
  if (key.startsWith('address.')) {
771
- addressData[key.replace(/^address\./, '')] = val;
779
+ if (val !== '' && val !== null && val !== undefined) {
780
+ addressData[key.replace(/^address\./, '')] = val;
781
+ }
772
782
  continue;
773
783
  }
774
784
  /* Prefijo dinámico */
@@ -789,38 +799,50 @@ class CiviCrm {
789
799
  addressLocationName = mappedLocationName;
790
800
  }
791
801
  if (root === 'email') {
792
- if (!subfield)
793
- emailData.email = val;
794
- else
795
- emailData[subfield] = val;
802
+ if (val !== '' && val !== null && val !== undefined) {
803
+ if (!subfield)
804
+ emailData.email = val;
805
+ else
806
+ emailData[subfield] = val;
807
+ }
796
808
  continue;
797
809
  }
798
810
  if (root === 'phone') {
799
- if (!subfield)
800
- phoneData.phone = val;
801
- else
802
- phoneData[subfield] = val;
811
+ if (val !== '' && val !== null && val !== undefined) {
812
+ if (!subfield)
813
+ phoneData.phone = val;
814
+ else
815
+ phoneData[subfield] = val;
816
+ }
803
817
  continue;
804
818
  }
805
819
  if (root === 'address') {
806
- if (subfield)
807
- addressData[subfield] = val;
820
+ if (val !== '' && val !== null && val !== undefined) {
821
+ if (subfield)
822
+ addressData[subfield] = val;
823
+ }
808
824
  continue;
809
825
  }
810
826
  }
811
827
  }
812
828
  /* gender */
813
829
  if (key === 'gender' || key === 'gender_id') {
814
- values.gender_id = val;
830
+ if (val !== '' && val !== null && val !== undefined) {
831
+ values.gender_id = val;
832
+ }
815
833
  continue;
816
834
  }
817
835
  /* birth_date */
818
836
  if (key === 'birth_date' || key === 'birth') {
819
- values.birth_date = normalizeBirthDate(String(val));
837
+ if (val !== '' && val !== null && val !== undefined) {
838
+ values.birth_date = normalizeBirthDate(String(val));
839
+ }
820
840
  continue;
821
841
  }
822
842
  /* default */
823
- values[key] = val;
843
+ if (val !== '' && val !== null && val !== undefined) {
844
+ values[key] = val;
845
+ }
824
846
  }
825
847
  /* Contact type */
826
848
  const contactType = this.getNodeParameter('contactType', i, '');
@@ -843,7 +865,7 @@ class CiviCrm {
843
865
  }
844
866
  /* SUBENTITIES */
845
867
  if (resource === 'contact') {
846
- if (isPrimary) {
868
+ if (isCreate && isPrimary) {
847
869
  await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/delete', {
848
870
  where: [
849
871
  ['contact_id', '=', contactId],
@@ -868,7 +890,7 @@ class CiviCrm {
868
890
  values: {
869
891
  ...emailData,
870
892
  contact_id: contactId,
871
- is_primary: isPrimary,
893
+ is_primary: isCreate ? isPrimary : false,
872
894
  'location_type_id:name': emailLocationName,
873
895
  },
874
896
  });
@@ -878,7 +900,7 @@ class CiviCrm {
878
900
  values: {
879
901
  ...phoneData,
880
902
  contact_id: contactId,
881
- is_primary: isPrimary,
903
+ is_primary: isCreate ? isPrimary : false,
882
904
  'location_type_id:name': phoneLocationName,
883
905
  },
884
906
  });
@@ -888,7 +910,7 @@ class CiviCrm {
888
910
  values: {
889
911
  ...addressData,
890
912
  contact_id: contactId,
891
- is_primary: isPrimary,
913
+ is_primary: isCreate ? isPrimary : false,
892
914
  'location_type_id:name': addressLocationName,
893
915
  },
894
916
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixiam/n8n-nodes-civicrm",
3
- "version": "1.1.34",
3
+ "version": "1.1.35",
4
4
  "description": "Full-featured CiviCRM API v4 integration for n8n with support for Contacts, Memberships, Groups, Relationships, Activities and structured sub-entities like Email, Phone, and Address.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -858,27 +858,37 @@ export class CiviCrm implements INodeType {
858
858
 
859
859
  /* Email simple */
860
860
  if (key === 'email') {
861
- emailData.email = val;
861
+ if (val !== '' && val !== null && val !== undefined) {
862
+ emailData.email = val;
863
+ }
862
864
  continue;
863
865
  }
864
866
  if (key.startsWith('email.')) {
865
- emailData[key.replace(/^email\./, '')] = val;
867
+ if (val !== '' && val !== null && val !== undefined) {
868
+ emailData[key.replace(/^email\./, '')] = val;
869
+ }
866
870
  continue;
867
871
  }
868
872
 
869
873
  /* Phone simple */
870
874
  if (key === 'phone') {
871
- phoneData.phone = val;
875
+ if (val !== '' && val !== null && val !== undefined) {
876
+ phoneData.phone = val;
877
+ }
872
878
  continue;
873
879
  }
874
880
  if (key.startsWith('phone.')) {
875
- phoneData[key.replace(/^phone\./, '')] = val;
881
+ if (val !== '' && val !== null && val !== undefined) {
882
+ phoneData[key.replace(/^phone\./, '')] = val;
883
+ }
876
884
  continue;
877
885
  }
878
886
 
879
887
  /* Address */
880
888
  if (key.startsWith('address.')) {
881
- addressData[key.replace(/^address\./, '')] = val;
889
+ if (val !== '' && val !== null && val !== undefined) {
890
+ addressData[key.replace(/^address\./, '')] = val;
891
+ }
882
892
  continue;
883
893
  }
884
894
 
@@ -900,19 +910,25 @@ export class CiviCrm implements INodeType {
900
910
  }
901
911
 
902
912
  if (root === 'email') {
903
- if (!subfield) emailData.email = val;
904
- else emailData[subfield] = val;
913
+ if (val !== '' && val !== null && val !== undefined) {
914
+ if (!subfield) emailData.email = val;
915
+ else emailData[subfield] = val;
916
+ }
905
917
  continue;
906
918
  }
907
919
 
908
920
  if (root === 'phone') {
909
- if (!subfield) phoneData.phone = val;
910
- else phoneData[subfield] = val;
921
+ if (val !== '' && val !== null && val !== undefined) {
922
+ if (!subfield) phoneData.phone = val;
923
+ else phoneData[subfield] = val;
924
+ }
911
925
  continue;
912
926
  }
913
927
 
914
928
  if (root === 'address') {
915
- if (subfield) addressData[subfield] = val;
929
+ if (val !== '' && val !== null && val !== undefined) {
930
+ if (subfield) addressData[subfield] = val;
931
+ }
916
932
  continue;
917
933
  }
918
934
  }
@@ -920,18 +936,24 @@ export class CiviCrm implements INodeType {
920
936
 
921
937
  /* gender */
922
938
  if (key === 'gender' || key === 'gender_id') {
923
- values.gender_id = val;
939
+ if (val !== '' && val !== null && val !== undefined) {
940
+ values.gender_id = val;
941
+ }
924
942
  continue;
925
943
  }
926
944
 
927
945
  /* birth_date */
928
946
  if (key === 'birth_date' || key === 'birth') {
929
- values.birth_date = normalizeBirthDate(String(val));
947
+ if (val !== '' && val !== null && val !== undefined) {
948
+ values.birth_date = normalizeBirthDate(String(val));
949
+ }
930
950
  continue;
931
951
  }
932
952
 
933
953
  /* default */
934
- values[key] = val;
954
+ if (val !== '' && val !== null && val !== undefined) {
955
+ values[key] = val;
956
+ }
935
957
  }
936
958
 
937
959
  /* Contact type */
@@ -965,7 +987,7 @@ export class CiviCrm implements INodeType {
965
987
 
966
988
  /* SUBENTITIES */
967
989
  if (resource === 'contact') {
968
- if (isPrimary) {
990
+ if (isCreate && isPrimary) {
969
991
  await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/delete', {
970
992
  where: [
971
993
  ['contact_id', '=', contactId],
@@ -991,7 +1013,7 @@ export class CiviCrm implements INodeType {
991
1013
  values: {
992
1014
  ...emailData,
993
1015
  contact_id: contactId,
994
- is_primary: isPrimary,
1016
+ is_primary: isCreate ? isPrimary : false,
995
1017
  'location_type_id:name': emailLocationName,
996
1018
  },
997
1019
  });
@@ -1002,7 +1024,7 @@ export class CiviCrm implements INodeType {
1002
1024
  values: {
1003
1025
  ...phoneData,
1004
1026
  contact_id: contactId,
1005
- is_primary: isPrimary,
1027
+ is_primary: isCreate ? isPrimary : false,
1006
1028
  'location_type_id:name': phoneLocationName,
1007
1029
  },
1008
1030
  });
@@ -1013,7 +1035,7 @@ export class CiviCrm implements INodeType {
1013
1035
  values: {
1014
1036
  ...addressData,
1015
1037
  contact_id: contactId,
1016
- is_primary: isPrimary,
1038
+ is_primary: isCreate ? isPrimary : false,
1017
1039
  'location_type_id:name': addressLocationName,
1018
1040
  },
1019
1041
  });