@ixiam/n8n-nodes-civicrm 1.1.35 → 1.1.41
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.
|
@@ -445,6 +445,14 @@ class CiviCrm {
|
|
|
445
445
|
],
|
|
446
446
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
447
447
|
},
|
|
448
|
+
{
|
|
449
|
+
displayName: 'Mark Email as Primary',
|
|
450
|
+
name: 'isPrimaryEmail',
|
|
451
|
+
type: 'boolean',
|
|
452
|
+
default: true,
|
|
453
|
+
description: 'Whether this email should be the primary email for the contact.',
|
|
454
|
+
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
455
|
+
},
|
|
448
456
|
{
|
|
449
457
|
displayName: 'Phone Location Type',
|
|
450
458
|
name: 'phoneLocation',
|
|
@@ -459,6 +467,14 @@ class CiviCrm {
|
|
|
459
467
|
],
|
|
460
468
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
461
469
|
},
|
|
470
|
+
{
|
|
471
|
+
displayName: 'Mark Phone as Primary',
|
|
472
|
+
name: 'isPrimaryPhone',
|
|
473
|
+
type: 'boolean',
|
|
474
|
+
default: true,
|
|
475
|
+
description: 'Whether this phone should be the primary phone for the contact.',
|
|
476
|
+
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
477
|
+
},
|
|
462
478
|
{
|
|
463
479
|
displayName: 'Address Location Type',
|
|
464
480
|
name: 'addressLocation',
|
|
@@ -473,15 +489,12 @@ class CiviCrm {
|
|
|
473
489
|
],
|
|
474
490
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
475
491
|
},
|
|
476
|
-
//
|
|
477
|
-
// PRIMARY FLAG
|
|
478
|
-
//
|
|
479
492
|
{
|
|
480
|
-
displayName: 'Mark as Primary',
|
|
481
|
-
name: '
|
|
493
|
+
displayName: 'Mark Address as Primary',
|
|
494
|
+
name: 'isPrimaryAddress',
|
|
482
495
|
type: 'boolean',
|
|
483
496
|
default: true,
|
|
484
|
-
description: 'Whether this should be the primary
|
|
497
|
+
description: 'Whether this address should be the primary address for the contact.',
|
|
485
498
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
486
499
|
},
|
|
487
500
|
//
|
|
@@ -570,7 +583,7 @@ class CiviCrm {
|
|
|
570
583
|
EXECUTE
|
|
571
584
|
============================================================================ */
|
|
572
585
|
async execute() {
|
|
573
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
586
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
574
587
|
const items = this.getInputData();
|
|
575
588
|
const out = [];
|
|
576
589
|
const resource = this.getNodeParameter('resource', 0);
|
|
@@ -591,7 +604,10 @@ class CiviCrm {
|
|
|
591
604
|
}
|
|
592
605
|
const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/${action}`, params);
|
|
593
606
|
// Return the raw API4 response so advanced users can work with values and metadata
|
|
594
|
-
out.push({
|
|
607
|
+
out.push({
|
|
608
|
+
json: res,
|
|
609
|
+
pairedItem: { item: 0 },
|
|
610
|
+
});
|
|
595
611
|
return [out];
|
|
596
612
|
}
|
|
597
613
|
const entity = ENTITY_MAP[resource];
|
|
@@ -599,7 +615,9 @@ class CiviCrm {
|
|
|
599
615
|
const emailLocationParam = this.getNodeParameter('emailLocation', i, 'Work');
|
|
600
616
|
const phoneLocationParam = this.getNodeParameter('phoneLocation', i, 'Work');
|
|
601
617
|
const addressLocationParam = this.getNodeParameter('addressLocation', i, 'Home');
|
|
602
|
-
const
|
|
618
|
+
const isPrimaryEmail = this.getNodeParameter('isPrimaryEmail', i, true);
|
|
619
|
+
const isPrimaryPhone = this.getNodeParameter('isPrimaryPhone', i, true);
|
|
620
|
+
const isPrimaryAddress = this.getNodeParameter('isPrimaryAddress', i, true);
|
|
603
621
|
let emailLocationName = emailLocationParam;
|
|
604
622
|
let phoneLocationName = phoneLocationParam;
|
|
605
623
|
let addressLocationName = addressLocationParam;
|
|
@@ -636,7 +654,10 @@ class CiviCrm {
|
|
|
636
654
|
select: ['id', 'name', 'title', 'subject', 'display_name'],
|
|
637
655
|
};
|
|
638
656
|
const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, params);
|
|
639
|
-
out.push({
|
|
657
|
+
out.push({
|
|
658
|
+
json: (_b = (_a = res === null || res === void 0 ? void 0 : res.values) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : {},
|
|
659
|
+
pairedItem: { item: i },
|
|
660
|
+
});
|
|
640
661
|
continue;
|
|
641
662
|
}
|
|
642
663
|
/* ======================================================
|
|
@@ -692,8 +713,12 @@ class CiviCrm {
|
|
|
692
713
|
while (hasMore) {
|
|
693
714
|
const r = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, { ...params, limit: page, offset });
|
|
694
715
|
const vals = (_c = r === null || r === void 0 ? void 0 : r.values) !== null && _c !== void 0 ? _c : [];
|
|
695
|
-
for (const v of vals)
|
|
696
|
-
out.push({
|
|
716
|
+
for (const v of vals) {
|
|
717
|
+
out.push({
|
|
718
|
+
json: v,
|
|
719
|
+
pairedItem: { item: i },
|
|
720
|
+
});
|
|
721
|
+
}
|
|
697
722
|
if (vals.length < page) {
|
|
698
723
|
hasMore = false;
|
|
699
724
|
}
|
|
@@ -705,8 +730,12 @@ class CiviCrm {
|
|
|
705
730
|
else {
|
|
706
731
|
const r = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, { ...params, limit });
|
|
707
732
|
const vals = (_d = r === null || r === void 0 ? void 0 : r.values) !== null && _d !== void 0 ? _d : [];
|
|
708
|
-
for (const v of vals)
|
|
709
|
-
out.push({
|
|
733
|
+
for (const v of vals) {
|
|
734
|
+
out.push({
|
|
735
|
+
json: v,
|
|
736
|
+
pairedItem: { item: i },
|
|
737
|
+
});
|
|
738
|
+
}
|
|
710
739
|
}
|
|
711
740
|
continue;
|
|
712
741
|
}
|
|
@@ -725,6 +754,7 @@ class CiviCrm {
|
|
|
725
754
|
deleted_id: id,
|
|
726
755
|
api_response: r,
|
|
727
756
|
},
|
|
757
|
+
pairedItem: { item: i },
|
|
728
758
|
});
|
|
729
759
|
continue;
|
|
730
760
|
}
|
|
@@ -865,19 +895,23 @@ class CiviCrm {
|
|
|
865
895
|
}
|
|
866
896
|
/* SUBENTITIES */
|
|
867
897
|
if (resource === 'contact') {
|
|
868
|
-
if (isCreate &&
|
|
898
|
+
if (isCreate && isPrimaryEmail) {
|
|
869
899
|
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/delete', {
|
|
870
900
|
where: [
|
|
871
901
|
['contact_id', '=', contactId],
|
|
872
902
|
['is_primary', '=', true],
|
|
873
903
|
],
|
|
874
904
|
});
|
|
905
|
+
}
|
|
906
|
+
if (isCreate && isPrimaryPhone) {
|
|
875
907
|
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/delete', {
|
|
876
908
|
where: [
|
|
877
909
|
['contact_id', '=', contactId],
|
|
878
910
|
['is_primary', '=', true],
|
|
879
911
|
],
|
|
880
912
|
});
|
|
913
|
+
}
|
|
914
|
+
if (isCreate && isPrimaryAddress) {
|
|
881
915
|
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/delete', {
|
|
882
916
|
where: [
|
|
883
917
|
['contact_id', '=', contactId],
|
|
@@ -886,34 +920,133 @@ class CiviCrm {
|
|
|
886
920
|
});
|
|
887
921
|
}
|
|
888
922
|
if (Object.keys(emailData).length) {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
923
|
+
if (isCreate) {
|
|
924
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/create', {
|
|
925
|
+
values: {
|
|
926
|
+
...emailData,
|
|
927
|
+
contact_id: contactId,
|
|
928
|
+
is_primary: isPrimaryEmail,
|
|
929
|
+
'location_type_id:name': emailLocationName,
|
|
930
|
+
},
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
const existingEmail = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/get', {
|
|
935
|
+
where: [
|
|
936
|
+
['contact_id', '=', contactId],
|
|
937
|
+
['location_type_id:name', '=', emailLocationName],
|
|
938
|
+
],
|
|
939
|
+
limit: 1,
|
|
940
|
+
select: ['id'],
|
|
941
|
+
});
|
|
942
|
+
const existingEmailId = (_h = (_g = existingEmail === null || existingEmail === void 0 ? void 0 : existingEmail.values) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.id;
|
|
943
|
+
if (existingEmailId) {
|
|
944
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/update', {
|
|
945
|
+
values: {
|
|
946
|
+
id: existingEmailId,
|
|
947
|
+
...emailData,
|
|
948
|
+
contact_id: contactId,
|
|
949
|
+
is_primary: isPrimaryEmail,
|
|
950
|
+
},
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/create', {
|
|
955
|
+
values: {
|
|
956
|
+
...emailData,
|
|
957
|
+
contact_id: contactId,
|
|
958
|
+
is_primary: isPrimaryEmail,
|
|
959
|
+
'location_type_id:name': emailLocationName,
|
|
960
|
+
},
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
}
|
|
897
964
|
}
|
|
898
965
|
if (Object.keys(phoneData).length) {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
966
|
+
if (isCreate) {
|
|
967
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/create', {
|
|
968
|
+
values: {
|
|
969
|
+
...phoneData,
|
|
970
|
+
contact_id: contactId,
|
|
971
|
+
is_primary: isPrimaryPhone,
|
|
972
|
+
'location_type_id:name': phoneLocationName,
|
|
973
|
+
},
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
const existingPhone = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/get', {
|
|
978
|
+
where: [
|
|
979
|
+
['contact_id', '=', contactId],
|
|
980
|
+
['location_type_id:name', '=', phoneLocationName],
|
|
981
|
+
],
|
|
982
|
+
limit: 1,
|
|
983
|
+
select: ['id'],
|
|
984
|
+
});
|
|
985
|
+
const existingPhoneId = (_k = (_j = existingPhone === null || existingPhone === void 0 ? void 0 : existingPhone.values) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.id;
|
|
986
|
+
if (existingPhoneId) {
|
|
987
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/update', {
|
|
988
|
+
values: {
|
|
989
|
+
id: existingPhoneId,
|
|
990
|
+
...phoneData,
|
|
991
|
+
contact_id: contactId,
|
|
992
|
+
is_primary: isPrimaryPhone,
|
|
993
|
+
},
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/create', {
|
|
998
|
+
values: {
|
|
999
|
+
...phoneData,
|
|
1000
|
+
contact_id: contactId,
|
|
1001
|
+
is_primary: isPrimaryPhone,
|
|
1002
|
+
'location_type_id:name': phoneLocationName,
|
|
1003
|
+
},
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
907
1007
|
}
|
|
908
1008
|
if (Object.keys(addressData).length) {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1009
|
+
if (isCreate) {
|
|
1010
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/create', {
|
|
1011
|
+
values: {
|
|
1012
|
+
...addressData,
|
|
1013
|
+
contact_id: contactId,
|
|
1014
|
+
is_primary: isPrimaryAddress,
|
|
1015
|
+
'location_type_id:name': addressLocationName,
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
else {
|
|
1020
|
+
const existingAddress = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/get', {
|
|
1021
|
+
where: [
|
|
1022
|
+
['contact_id', '=', contactId],
|
|
1023
|
+
['location_type_id:name', '=', addressLocationName],
|
|
1024
|
+
],
|
|
1025
|
+
limit: 1,
|
|
1026
|
+
select: ['id'],
|
|
1027
|
+
});
|
|
1028
|
+
const existingAddressId = (_m = (_l = existingAddress === null || existingAddress === void 0 ? void 0 : existingAddress.values) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.id;
|
|
1029
|
+
if (existingAddressId) {
|
|
1030
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/update', {
|
|
1031
|
+
values: {
|
|
1032
|
+
id: existingAddressId,
|
|
1033
|
+
...addressData,
|
|
1034
|
+
contact_id: contactId,
|
|
1035
|
+
is_primary: isPrimaryAddress,
|
|
1036
|
+
},
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/create', {
|
|
1041
|
+
values: {
|
|
1042
|
+
...addressData,
|
|
1043
|
+
contact_id: contactId,
|
|
1044
|
+
is_primary: isPrimaryAddress,
|
|
1045
|
+
'location_type_id:name': addressLocationName,
|
|
1046
|
+
},
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
917
1050
|
}
|
|
918
1051
|
}
|
|
919
1052
|
/* FINAL GET */
|
|
@@ -941,7 +1074,10 @@ class CiviCrm {
|
|
|
941
1074
|
}
|
|
942
1075
|
: {}),
|
|
943
1076
|
});
|
|
944
|
-
out.push({
|
|
1077
|
+
out.push({
|
|
1078
|
+
json: (_p = (_o = res === null || res === void 0 ? void 0 : res.values) === null || _o === void 0 ? void 0 : _o[0]) !== null && _p !== void 0 ? _p : {},
|
|
1079
|
+
pairedItem: { item: i },
|
|
1080
|
+
});
|
|
945
1081
|
}
|
|
946
1082
|
return [out];
|
|
947
1083
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixiam/n8n-nodes-civicrm",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Full-featured CiviCRM API v4 integration for n8n
|
|
3
|
+
"version": "1.1.41",
|
|
4
|
+
"description": "Full-featured CiviCRM API v4 integration for n8n",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"n8n-community-node-package",
|
|
@@ -482,6 +482,14 @@ export class CiviCrm implements INodeType {
|
|
|
482
482
|
],
|
|
483
483
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
484
484
|
},
|
|
485
|
+
{
|
|
486
|
+
displayName: 'Mark Email as Primary',
|
|
487
|
+
name: 'isPrimaryEmail',
|
|
488
|
+
type: 'boolean',
|
|
489
|
+
default: true,
|
|
490
|
+
description: 'Whether this email should be the primary email for the contact.',
|
|
491
|
+
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
492
|
+
},
|
|
485
493
|
{
|
|
486
494
|
displayName: 'Phone Location Type',
|
|
487
495
|
name: 'phoneLocation',
|
|
@@ -496,6 +504,14 @@ export class CiviCrm implements INodeType {
|
|
|
496
504
|
],
|
|
497
505
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
498
506
|
},
|
|
507
|
+
{
|
|
508
|
+
displayName: 'Mark Phone as Primary',
|
|
509
|
+
name: 'isPrimaryPhone',
|
|
510
|
+
type: 'boolean',
|
|
511
|
+
default: true,
|
|
512
|
+
description: 'Whether this phone should be the primary phone for the contact.',
|
|
513
|
+
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
514
|
+
},
|
|
499
515
|
{
|
|
500
516
|
displayName: 'Address Location Type',
|
|
501
517
|
name: 'addressLocation',
|
|
@@ -510,16 +526,12 @@ export class CiviCrm implements INodeType {
|
|
|
510
526
|
],
|
|
511
527
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
512
528
|
},
|
|
513
|
-
|
|
514
|
-
//
|
|
515
|
-
// PRIMARY FLAG
|
|
516
|
-
//
|
|
517
529
|
{
|
|
518
|
-
displayName: 'Mark as Primary',
|
|
519
|
-
name: '
|
|
530
|
+
displayName: 'Mark Address as Primary',
|
|
531
|
+
name: 'isPrimaryAddress',
|
|
520
532
|
type: 'boolean',
|
|
521
533
|
default: true,
|
|
522
|
-
description: 'Whether this should be the primary
|
|
534
|
+
description: 'Whether this address should be the primary address for the contact.',
|
|
523
535
|
displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
|
|
524
536
|
},
|
|
525
537
|
|
|
@@ -652,7 +664,10 @@ export class CiviCrm implements INodeType {
|
|
|
652
664
|
);
|
|
653
665
|
|
|
654
666
|
// Return the raw API4 response so advanced users can work with values and metadata
|
|
655
|
-
out.push({
|
|
667
|
+
out.push({
|
|
668
|
+
json: res as IDataObject,
|
|
669
|
+
pairedItem: { item: 0 },
|
|
670
|
+
});
|
|
656
671
|
return [out];
|
|
657
672
|
}
|
|
658
673
|
|
|
@@ -662,7 +677,9 @@ export class CiviCrm implements INodeType {
|
|
|
662
677
|
const emailLocationParam = this.getNodeParameter('emailLocation', i, 'Work') as string;
|
|
663
678
|
const phoneLocationParam = this.getNodeParameter('phoneLocation', i, 'Work') as string;
|
|
664
679
|
const addressLocationParam = this.getNodeParameter('addressLocation', i, 'Home') as string;
|
|
665
|
-
const
|
|
680
|
+
const isPrimaryEmail = this.getNodeParameter('isPrimaryEmail', i, true) as boolean;
|
|
681
|
+
const isPrimaryPhone = this.getNodeParameter('isPrimaryPhone', i, true) as boolean;
|
|
682
|
+
const isPrimaryAddress = this.getNodeParameter('isPrimaryAddress', i, true) as boolean;
|
|
666
683
|
|
|
667
684
|
let emailLocationName = emailLocationParam;
|
|
668
685
|
let phoneLocationName = phoneLocationParam;
|
|
@@ -710,7 +727,10 @@ export class CiviCrm implements INodeType {
|
|
|
710
727
|
params,
|
|
711
728
|
);
|
|
712
729
|
|
|
713
|
-
out.push({
|
|
730
|
+
out.push({
|
|
731
|
+
json: res?.values?.[0] ?? {},
|
|
732
|
+
pairedItem: { item: i },
|
|
733
|
+
});
|
|
714
734
|
continue;
|
|
715
735
|
}
|
|
716
736
|
|
|
@@ -777,7 +797,12 @@ export class CiviCrm implements INodeType {
|
|
|
777
797
|
);
|
|
778
798
|
|
|
779
799
|
const vals = r?.values ?? [];
|
|
780
|
-
for (const v of vals)
|
|
800
|
+
for (const v of vals) {
|
|
801
|
+
out.push({
|
|
802
|
+
json: v,
|
|
803
|
+
pairedItem: { item: i },
|
|
804
|
+
});
|
|
805
|
+
}
|
|
781
806
|
|
|
782
807
|
if (vals.length < page) {
|
|
783
808
|
hasMore = false;
|
|
@@ -794,7 +819,12 @@ export class CiviCrm implements INodeType {
|
|
|
794
819
|
);
|
|
795
820
|
|
|
796
821
|
const vals = r?.values ?? [];
|
|
797
|
-
for (const v of vals)
|
|
822
|
+
for (const v of vals) {
|
|
823
|
+
out.push({
|
|
824
|
+
json: v,
|
|
825
|
+
pairedItem: { item: i },
|
|
826
|
+
});
|
|
827
|
+
}
|
|
798
828
|
}
|
|
799
829
|
|
|
800
830
|
continue;
|
|
@@ -822,6 +852,7 @@ export class CiviCrm implements INodeType {
|
|
|
822
852
|
deleted_id: id,
|
|
823
853
|
api_response: r,
|
|
824
854
|
},
|
|
855
|
+
pairedItem: { item: i },
|
|
825
856
|
});
|
|
826
857
|
|
|
827
858
|
continue;
|
|
@@ -987,19 +1018,23 @@ export class CiviCrm implements INodeType {
|
|
|
987
1018
|
|
|
988
1019
|
/* SUBENTITIES */
|
|
989
1020
|
if (resource === 'contact') {
|
|
990
|
-
if (isCreate &&
|
|
1021
|
+
if (isCreate && isPrimaryEmail) {
|
|
991
1022
|
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/delete', {
|
|
992
1023
|
where: [
|
|
993
1024
|
['contact_id', '=', contactId],
|
|
994
1025
|
['is_primary', '=', true],
|
|
995
1026
|
],
|
|
996
1027
|
});
|
|
1028
|
+
}
|
|
1029
|
+
if (isCreate && isPrimaryPhone) {
|
|
997
1030
|
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/delete', {
|
|
998
1031
|
where: [
|
|
999
1032
|
['contact_id', '=', contactId],
|
|
1000
1033
|
['is_primary', '=', true],
|
|
1001
1034
|
],
|
|
1002
1035
|
});
|
|
1036
|
+
}
|
|
1037
|
+
if (isCreate && isPrimaryAddress) {
|
|
1003
1038
|
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/delete', {
|
|
1004
1039
|
where: [
|
|
1005
1040
|
['contact_id', '=', contactId],
|
|
@@ -1009,36 +1044,130 @@ export class CiviCrm implements INodeType {
|
|
|
1009
1044
|
}
|
|
1010
1045
|
|
|
1011
1046
|
if (Object.keys(emailData).length) {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1047
|
+
if (isCreate) {
|
|
1048
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/create', {
|
|
1049
|
+
values: {
|
|
1050
|
+
...emailData,
|
|
1051
|
+
contact_id: contactId,
|
|
1052
|
+
is_primary: isPrimaryEmail,
|
|
1053
|
+
'location_type_id:name': emailLocationName,
|
|
1054
|
+
},
|
|
1055
|
+
});
|
|
1056
|
+
} else {
|
|
1057
|
+
const existingEmail = await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/get', {
|
|
1058
|
+
where: [
|
|
1059
|
+
['contact_id', '=', contactId],
|
|
1060
|
+
['location_type_id:name', '=', emailLocationName],
|
|
1061
|
+
],
|
|
1062
|
+
limit: 1,
|
|
1063
|
+
select: ['id'],
|
|
1064
|
+
});
|
|
1065
|
+
const existingEmailId = existingEmail?.values?.[0]?.id as number | undefined;
|
|
1066
|
+
if (existingEmailId) {
|
|
1067
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/update', {
|
|
1068
|
+
values: {
|
|
1069
|
+
id: existingEmailId,
|
|
1070
|
+
...emailData,
|
|
1071
|
+
contact_id: contactId,
|
|
1072
|
+
is_primary: isPrimaryEmail,
|
|
1073
|
+
},
|
|
1074
|
+
});
|
|
1075
|
+
} else {
|
|
1076
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Email/create', {
|
|
1077
|
+
values: {
|
|
1078
|
+
...emailData,
|
|
1079
|
+
contact_id: contactId,
|
|
1080
|
+
is_primary: isPrimaryEmail,
|
|
1081
|
+
'location_type_id:name': emailLocationName,
|
|
1082
|
+
},
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1020
1086
|
}
|
|
1021
1087
|
|
|
1022
1088
|
if (Object.keys(phoneData).length) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1089
|
+
if (isCreate) {
|
|
1090
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/create', {
|
|
1091
|
+
values: {
|
|
1092
|
+
...phoneData,
|
|
1093
|
+
contact_id: contactId,
|
|
1094
|
+
is_primary: isPrimaryPhone,
|
|
1095
|
+
'location_type_id:name': phoneLocationName,
|
|
1096
|
+
},
|
|
1097
|
+
});
|
|
1098
|
+
} else {
|
|
1099
|
+
const existingPhone = await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/get', {
|
|
1100
|
+
where: [
|
|
1101
|
+
['contact_id', '=', contactId],
|
|
1102
|
+
['location_type_id:name', '=', phoneLocationName],
|
|
1103
|
+
],
|
|
1104
|
+
limit: 1,
|
|
1105
|
+
select: ['id'],
|
|
1106
|
+
});
|
|
1107
|
+
const existingPhoneId = existingPhone?.values?.[0]?.id as number | undefined;
|
|
1108
|
+
if (existingPhoneId) {
|
|
1109
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/update', {
|
|
1110
|
+
values: {
|
|
1111
|
+
id: existingPhoneId,
|
|
1112
|
+
...phoneData,
|
|
1113
|
+
contact_id: contactId,
|
|
1114
|
+
is_primary: isPrimaryPhone,
|
|
1115
|
+
},
|
|
1116
|
+
});
|
|
1117
|
+
} else {
|
|
1118
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Phone/create', {
|
|
1119
|
+
values: {
|
|
1120
|
+
...phoneData,
|
|
1121
|
+
contact_id: contactId,
|
|
1122
|
+
is_primary: isPrimaryPhone,
|
|
1123
|
+
'location_type_id:name': phoneLocationName,
|
|
1124
|
+
},
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1031
1128
|
}
|
|
1032
1129
|
|
|
1130
|
+
|
|
1033
1131
|
if (Object.keys(addressData).length) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1132
|
+
if (isCreate) {
|
|
1133
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/create', {
|
|
1134
|
+
values: {
|
|
1135
|
+
...addressData,
|
|
1136
|
+
contact_id: contactId,
|
|
1137
|
+
is_primary: isPrimaryAddress,
|
|
1138
|
+
'location_type_id:name': addressLocationName,
|
|
1139
|
+
},
|
|
1140
|
+
});
|
|
1141
|
+
} else {
|
|
1142
|
+
const existingAddress = await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/get', {
|
|
1143
|
+
where: [
|
|
1144
|
+
['contact_id', '=', contactId],
|
|
1145
|
+
['location_type_id:name', '=', addressLocationName],
|
|
1146
|
+
],
|
|
1147
|
+
limit: 1,
|
|
1148
|
+
select: ['id'],
|
|
1149
|
+
});
|
|
1150
|
+
const existingAddressId = existingAddress?.values?.[0]?.id as number | undefined;
|
|
1151
|
+
if (existingAddressId) {
|
|
1152
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/update', {
|
|
1153
|
+
values: {
|
|
1154
|
+
id: existingAddressId,
|
|
1155
|
+
...addressData,
|
|
1156
|
+
contact_id: contactId,
|
|
1157
|
+
is_primary: isPrimaryAddress,
|
|
1158
|
+
},
|
|
1159
|
+
});
|
|
1160
|
+
} else {
|
|
1161
|
+
await civicrmApiRequest.call(this, 'POST', '/civicrm/ajax/api4/Address/create', {
|
|
1162
|
+
values: {
|
|
1163
|
+
...addressData,
|
|
1164
|
+
contact_id: contactId,
|
|
1165
|
+
is_primary: isPrimaryAddress,
|
|
1166
|
+
'location_type_id:name': addressLocationName,
|
|
1167
|
+
},
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1042
1171
|
}
|
|
1043
1172
|
}
|
|
1044
1173
|
|
|
@@ -1073,7 +1202,10 @@ export class CiviCrm implements INodeType {
|
|
|
1073
1202
|
},
|
|
1074
1203
|
);
|
|
1075
1204
|
|
|
1076
|
-
out.push({
|
|
1205
|
+
out.push({
|
|
1206
|
+
json: res?.values?.[0] ?? {},
|
|
1207
|
+
pairedItem: { item: i },
|
|
1208
|
+
});
|
|
1077
1209
|
}
|
|
1078
1210
|
|
|
1079
1211
|
return [out];
|