n8n-nodes-aivencerealtycrm 1.1.0 → 1.3.0
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/dist/nodes/AivenceRealty/AivenceRealty.node.js +264 -6
- package/dist/nodes/AivenceRealtyTrigger/AivenceRealtyTrigger.node.d.ts +12 -0
- package/dist/nodes/AivenceRealtyTrigger/AivenceRealtyTrigger.node.js +271 -0
- package/dist/nodes/AivenceRealtyTrigger/aivencerealty.png +0 -0
- package/package.json +3 -2
|
@@ -759,6 +759,145 @@ class AivenceRealty {
|
|
|
759
759
|
default: '',
|
|
760
760
|
description: 'ID del contratista a asignar',
|
|
761
761
|
},
|
|
762
|
+
// ============================================
|
|
763
|
+
// MAINTENANCE REQUEST LIST FILTERS
|
|
764
|
+
// ============================================
|
|
765
|
+
{
|
|
766
|
+
displayName: 'Property ID Filter',
|
|
767
|
+
name: 'propertyIdFilter',
|
|
768
|
+
type: 'string',
|
|
769
|
+
displayOptions: {
|
|
770
|
+
show: {
|
|
771
|
+
resource: ['maintenanceRequest'],
|
|
772
|
+
operation: ['list'],
|
|
773
|
+
},
|
|
774
|
+
},
|
|
775
|
+
default: '',
|
|
776
|
+
description: 'Filtrar por ID de propiedad',
|
|
777
|
+
placeholder: '={{ $json.property_id }}',
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
displayName: 'Status Filter',
|
|
781
|
+
name: 'statusFilter',
|
|
782
|
+
type: 'options',
|
|
783
|
+
options: [
|
|
784
|
+
{
|
|
785
|
+
name: 'All',
|
|
786
|
+
value: '',
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
name: 'Pending',
|
|
790
|
+
value: 'pending',
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
name: 'In Progress',
|
|
794
|
+
value: 'in_progress',
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
name: 'Completed',
|
|
798
|
+
value: 'completed',
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: 'Cancelled',
|
|
802
|
+
value: 'cancelled',
|
|
803
|
+
},
|
|
804
|
+
],
|
|
805
|
+
displayOptions: {
|
|
806
|
+
show: {
|
|
807
|
+
resource: ['maintenanceRequest'],
|
|
808
|
+
operation: ['list'],
|
|
809
|
+
},
|
|
810
|
+
},
|
|
811
|
+
default: '',
|
|
812
|
+
description: 'Filtrar por estado',
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
displayName: 'Tenant ID Filter',
|
|
816
|
+
name: 'tenantIdFilter',
|
|
817
|
+
type: 'string',
|
|
818
|
+
displayOptions: {
|
|
819
|
+
show: {
|
|
820
|
+
resource: ['maintenanceRequest'],
|
|
821
|
+
operation: ['list'],
|
|
822
|
+
},
|
|
823
|
+
},
|
|
824
|
+
default: '',
|
|
825
|
+
description: 'Filtrar por ID de inquilino',
|
|
826
|
+
placeholder: '={{ $json.tenant_id }}',
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
displayName: 'Priority Filter',
|
|
830
|
+
name: 'priorityFilter',
|
|
831
|
+
type: 'options',
|
|
832
|
+
options: [
|
|
833
|
+
{
|
|
834
|
+
name: 'All',
|
|
835
|
+
value: '',
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
name: 'Low',
|
|
839
|
+
value: 'low',
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
name: 'Medium',
|
|
843
|
+
value: 'medium',
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
name: 'High',
|
|
847
|
+
value: 'high',
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
name: 'Urgent',
|
|
851
|
+
value: 'urgent',
|
|
852
|
+
},
|
|
853
|
+
],
|
|
854
|
+
displayOptions: {
|
|
855
|
+
show: {
|
|
856
|
+
resource: ['maintenanceRequest'],
|
|
857
|
+
operation: ['list'],
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
default: '',
|
|
861
|
+
description: 'Filtrar por prioridad',
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
displayName: 'Limit',
|
|
865
|
+
name: 'limitMaintenance',
|
|
866
|
+
type: 'number',
|
|
867
|
+
typeOptions: {
|
|
868
|
+
minValue: 1,
|
|
869
|
+
maxValue: 100,
|
|
870
|
+
},
|
|
871
|
+
displayOptions: {
|
|
872
|
+
show: {
|
|
873
|
+
resource: ['maintenanceRequest'],
|
|
874
|
+
operation: ['list'],
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
default: 10,
|
|
878
|
+
description: 'Número máximo de resultados (1-100)',
|
|
879
|
+
},
|
|
880
|
+
// ============================================
|
|
881
|
+
// ADD MESSAGE FIELD
|
|
882
|
+
// ============================================
|
|
883
|
+
{
|
|
884
|
+
displayName: 'Message',
|
|
885
|
+
name: 'message',
|
|
886
|
+
type: 'string',
|
|
887
|
+
typeOptions: {
|
|
888
|
+
rows: 4,
|
|
889
|
+
},
|
|
890
|
+
required: true,
|
|
891
|
+
displayOptions: {
|
|
892
|
+
show: {
|
|
893
|
+
resource: ['maintenanceRequest'],
|
|
894
|
+
operation: ['addMessage'],
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
default: '',
|
|
898
|
+
description: 'Mensaje a agregar a la solicitud',
|
|
899
|
+
placeholder: '={{ $json.mensaje }}',
|
|
900
|
+
},
|
|
762
901
|
{
|
|
763
902
|
displayName: 'Modo de entrada',
|
|
764
903
|
name: 'useJsonInput',
|
|
@@ -766,7 +905,7 @@ class AivenceRealty {
|
|
|
766
905
|
displayOptions: {
|
|
767
906
|
show: {
|
|
768
907
|
resource: ['maintenanceRequest'],
|
|
769
|
-
operation: ['create', 'update'
|
|
908
|
+
operation: ['create', 'update'],
|
|
770
909
|
},
|
|
771
910
|
},
|
|
772
911
|
default: false,
|
|
@@ -828,6 +967,85 @@ class AivenceRealty {
|
|
|
828
967
|
default: '',
|
|
829
968
|
description: 'ID del contractor',
|
|
830
969
|
},
|
|
970
|
+
// ============================================
|
|
971
|
+
// CONTRACTOR LIST FILTERS
|
|
972
|
+
// ============================================
|
|
973
|
+
{
|
|
974
|
+
displayName: 'Specialization Filter',
|
|
975
|
+
name: 'specializationFilter',
|
|
976
|
+
type: 'string',
|
|
977
|
+
displayOptions: {
|
|
978
|
+
show: {
|
|
979
|
+
resource: ['contractor'],
|
|
980
|
+
operation: ['list', 'getNextAvailable'],
|
|
981
|
+
},
|
|
982
|
+
},
|
|
983
|
+
default: '',
|
|
984
|
+
description: 'Filtrar por especialización (plomería, electricidad, etc.)',
|
|
985
|
+
placeholder: '={{ $json.category }}',
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
displayName: 'Available Filter',
|
|
989
|
+
name: 'availableFilter',
|
|
990
|
+
type: 'boolean',
|
|
991
|
+
displayOptions: {
|
|
992
|
+
show: {
|
|
993
|
+
resource: ['contractor'],
|
|
994
|
+
operation: ['list'],
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
default: true,
|
|
998
|
+
description: 'Filtrar solo contractors disponibles',
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
displayName: 'City Filter',
|
|
1002
|
+
name: 'cityFilter',
|
|
1003
|
+
type: 'string',
|
|
1004
|
+
displayOptions: {
|
|
1005
|
+
show: {
|
|
1006
|
+
resource: ['contractor'],
|
|
1007
|
+
operation: ['list'],
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
default: '',
|
|
1011
|
+
description: 'Filtrar por ciudad',
|
|
1012
|
+
placeholder: 'Buenos Aires',
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
displayName: 'Rating Min Filter',
|
|
1016
|
+
name: 'ratingMinFilter',
|
|
1017
|
+
type: 'number',
|
|
1018
|
+
typeOptions: {
|
|
1019
|
+
minValue: 0,
|
|
1020
|
+
maxValue: 5,
|
|
1021
|
+
numberPrecision: 1,
|
|
1022
|
+
},
|
|
1023
|
+
displayOptions: {
|
|
1024
|
+
show: {
|
|
1025
|
+
resource: ['contractor'],
|
|
1026
|
+
operation: ['list'],
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
default: 0,
|
|
1030
|
+
description: 'Calificación mínima (0-5)',
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
displayName: 'Limit',
|
|
1034
|
+
name: 'limitContractor',
|
|
1035
|
+
type: 'number',
|
|
1036
|
+
typeOptions: {
|
|
1037
|
+
minValue: 1,
|
|
1038
|
+
maxValue: 100,
|
|
1039
|
+
},
|
|
1040
|
+
displayOptions: {
|
|
1041
|
+
show: {
|
|
1042
|
+
resource: ['contractor'],
|
|
1043
|
+
operation: ['list'],
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
default: 10,
|
|
1047
|
+
description: 'Número máximo de resultados (1-100)',
|
|
1048
|
+
},
|
|
831
1049
|
// Contractor Create: JSON from previous node
|
|
832
1050
|
{
|
|
833
1051
|
displayName: 'Modo de entrada',
|
|
@@ -1306,9 +1524,26 @@ class AivenceRealty {
|
|
|
1306
1524
|
// ============================================
|
|
1307
1525
|
else if (resource === 'maintenanceRequest') {
|
|
1308
1526
|
if (operation === 'list') {
|
|
1527
|
+
const propertyIdFilter = this.getNodeParameter('propertyIdFilter', i, '');
|
|
1528
|
+
const statusFilter = this.getNodeParameter('statusFilter', i, '');
|
|
1529
|
+
const tenantIdFilter = this.getNodeParameter('tenantIdFilter', i, '');
|
|
1530
|
+
const priorityFilter = this.getNodeParameter('priorityFilter', i, '');
|
|
1531
|
+
const limitMaintenance = this.getNodeParameter('limitMaintenance', i, 10);
|
|
1532
|
+
const queryParams = [];
|
|
1533
|
+
if (propertyIdFilter)
|
|
1534
|
+
queryParams.push(`property_id=${encodeURIComponent(propertyIdFilter)}`);
|
|
1535
|
+
if (statusFilter)
|
|
1536
|
+
queryParams.push(`status=${encodeURIComponent(statusFilter)}`);
|
|
1537
|
+
if (tenantIdFilter)
|
|
1538
|
+
queryParams.push(`tenant_id=${encodeURIComponent(tenantIdFilter)}`);
|
|
1539
|
+
if (priorityFilter)
|
|
1540
|
+
queryParams.push(`priority=${encodeURIComponent(priorityFilter)}`);
|
|
1541
|
+
if (limitMaintenance)
|
|
1542
|
+
queryParams.push(`per_page=${limitMaintenance}`);
|
|
1543
|
+
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
|
|
1309
1544
|
responseData = await this.helpers.httpRequest({
|
|
1310
1545
|
method: 'GET',
|
|
1311
|
-
url: `${baseUrl}/api/maintenance-requests`,
|
|
1546
|
+
url: `${baseUrl}/api/maintenance-requests${queryString}`,
|
|
1312
1547
|
json: true,
|
|
1313
1548
|
});
|
|
1314
1549
|
}
|
|
@@ -1343,8 +1578,10 @@ class AivenceRealty {
|
|
|
1343
1578
|
}
|
|
1344
1579
|
else if (operation === 'addMessage') {
|
|
1345
1580
|
const requestId = this.getNodeParameter('requestId', i);
|
|
1346
|
-
const
|
|
1347
|
-
const body =
|
|
1581
|
+
const message = this.getNodeParameter('message', i);
|
|
1582
|
+
const body = {
|
|
1583
|
+
message: message,
|
|
1584
|
+
};
|
|
1348
1585
|
responseData = await this.helpers.httpRequest({
|
|
1349
1586
|
method: 'PATCH',
|
|
1350
1587
|
url: `${baseUrl}/api/maintenance-requests/${requestId}/add-message`,
|
|
@@ -1368,9 +1605,25 @@ class AivenceRealty {
|
|
|
1368
1605
|
// ============================================
|
|
1369
1606
|
else if (resource === 'contractor') {
|
|
1370
1607
|
if (operation === 'list') {
|
|
1608
|
+
const specializationFilter = this.getNodeParameter('specializationFilter', i, '');
|
|
1609
|
+
const availableFilter = this.getNodeParameter('availableFilter', i, true);
|
|
1610
|
+
const cityFilter = this.getNodeParameter('cityFilter', i, '');
|
|
1611
|
+
const ratingMinFilter = this.getNodeParameter('ratingMinFilter', i, 0);
|
|
1612
|
+
const limitContractor = this.getNodeParameter('limitContractor', i, 10);
|
|
1613
|
+
const queryParams = [];
|
|
1614
|
+
if (specializationFilter)
|
|
1615
|
+
queryParams.push(`specialization=${encodeURIComponent(specializationFilter)}`);
|
|
1616
|
+
queryParams.push(`available=${availableFilter}`);
|
|
1617
|
+
if (cityFilter)
|
|
1618
|
+
queryParams.push(`city=${encodeURIComponent(cityFilter)}`);
|
|
1619
|
+
if (ratingMinFilter > 0)
|
|
1620
|
+
queryParams.push(`rating_min=${ratingMinFilter}`);
|
|
1621
|
+
if (limitContractor)
|
|
1622
|
+
queryParams.push(`limit=${limitContractor}`);
|
|
1623
|
+
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
|
|
1371
1624
|
responseData = await this.helpers.httpRequest({
|
|
1372
1625
|
method: 'GET',
|
|
1373
|
-
url: `${baseUrl}/api/
|
|
1626
|
+
url: `${baseUrl}/api/contractors${queryString}`,
|
|
1374
1627
|
json: true,
|
|
1375
1628
|
});
|
|
1376
1629
|
}
|
|
@@ -1393,9 +1646,14 @@ class AivenceRealty {
|
|
|
1393
1646
|
});
|
|
1394
1647
|
}
|
|
1395
1648
|
else if (operation === 'getNextAvailable') {
|
|
1649
|
+
const specializationFilter = this.getNodeParameter('specializationFilter', i, '');
|
|
1650
|
+
const queryParams = [];
|
|
1651
|
+
if (specializationFilter)
|
|
1652
|
+
queryParams.push(`category=${encodeURIComponent(specializationFilter)}`);
|
|
1653
|
+
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
|
|
1396
1654
|
responseData = await this.helpers.httpRequest({
|
|
1397
1655
|
method: 'GET',
|
|
1398
|
-
url: `${baseUrl}/api/contractors/next-available`,
|
|
1656
|
+
url: `${baseUrl}/api/contractors/next-available${queryString}`,
|
|
1399
1657
|
json: true,
|
|
1400
1658
|
});
|
|
1401
1659
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IHookFunctions, IWebhookFunctions, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
+
export declare class AivenceRealtyTrigger implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
webhookMethods: {
|
|
5
|
+
default: {
|
|
6
|
+
checkExists(this: IHookFunctions): Promise<boolean>;
|
|
7
|
+
create(this: IHookFunctions): Promise<boolean>;
|
|
8
|
+
delete(this: IHookFunctions): Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AivenceRealtyTrigger = void 0;
|
|
4
|
+
class AivenceRealtyTrigger {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.description = {
|
|
7
|
+
displayName: 'AivenceRealty Trigger',
|
|
8
|
+
name: 'aivenceRealtyTrigger',
|
|
9
|
+
icon: 'file:aivencerealty.png',
|
|
10
|
+
group: ['trigger'],
|
|
11
|
+
version: 1,
|
|
12
|
+
subtitle: '={{$parameter["event"]}}',
|
|
13
|
+
description: 'Trigger de eventos desde AivenceRealty CRM',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'AivenceRealty Trigger',
|
|
16
|
+
},
|
|
17
|
+
inputs: [],
|
|
18
|
+
outputs: ['main'],
|
|
19
|
+
credentials: [
|
|
20
|
+
{
|
|
21
|
+
name: 'aivenceRealtyApi',
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
webhooks: [
|
|
26
|
+
{
|
|
27
|
+
name: 'default',
|
|
28
|
+
httpMethod: 'POST',
|
|
29
|
+
responseMode: 'onReceived',
|
|
30
|
+
path: 'webhook',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
properties: [
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Evento',
|
|
36
|
+
name: 'event',
|
|
37
|
+
type: 'options',
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
name: 'Propiedad Creada',
|
|
41
|
+
value: 'property.created',
|
|
42
|
+
description: 'Se dispara cuando se crea una nueva propiedad',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Propiedad Actualizada',
|
|
46
|
+
value: 'property.updated',
|
|
47
|
+
description: 'Se dispara cuando se actualiza una propiedad',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'Lead Creado',
|
|
51
|
+
value: 'lead.created',
|
|
52
|
+
description: 'Se dispara cuando se crea un nuevo lead',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Lead Actualizado',
|
|
56
|
+
value: 'lead.updated',
|
|
57
|
+
description: 'Se dispara cuando se actualiza un lead',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'Email Recibido',
|
|
61
|
+
value: 'email.received',
|
|
62
|
+
description: 'Se dispara cuando se recibe un nuevo email',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'Maintenance Request Creada',
|
|
66
|
+
value: 'maintenance.created',
|
|
67
|
+
description: 'Se dispara cuando se crea una solicitud de mantenimiento',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'Appointment Creado',
|
|
71
|
+
value: 'appointment.created',
|
|
72
|
+
description: 'Se dispara cuando se crea una cita',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
default: 'property.created',
|
|
76
|
+
description: 'El evento que disparará el webhook',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Filtros Adicionales',
|
|
80
|
+
name: 'filters',
|
|
81
|
+
type: 'collection',
|
|
82
|
+
placeholder: 'Agregar Filtro',
|
|
83
|
+
default: {},
|
|
84
|
+
options: [
|
|
85
|
+
{
|
|
86
|
+
displayName: 'Property Type',
|
|
87
|
+
name: 'property_type',
|
|
88
|
+
type: 'options',
|
|
89
|
+
options: [
|
|
90
|
+
{
|
|
91
|
+
name: 'Apartamento',
|
|
92
|
+
value: 'apartamento',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'Casa',
|
|
96
|
+
value: 'casa',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'Loft',
|
|
100
|
+
value: 'loft',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'Terreno',
|
|
104
|
+
value: 'terreno',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'Oficina',
|
|
108
|
+
value: 'oficina',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
default: '',
|
|
112
|
+
description: 'Filtrar solo propiedades de este tipo',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Precio Mínimo',
|
|
116
|
+
name: 'price_min',
|
|
117
|
+
type: 'number',
|
|
118
|
+
default: 0,
|
|
119
|
+
description: 'Filtrar propiedades con precio mayor a este valor',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
displayName: 'Precio Máximo',
|
|
123
|
+
name: 'price_max',
|
|
124
|
+
type: 'number',
|
|
125
|
+
default: 0,
|
|
126
|
+
description: 'Filtrar propiedades con precio menor a este valor',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: 'Ciudad',
|
|
130
|
+
name: 'city',
|
|
131
|
+
type: 'string',
|
|
132
|
+
default: '',
|
|
133
|
+
description: 'Filtrar propiedades de esta ciudad',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
this.webhookMethods = {
|
|
140
|
+
default: {
|
|
141
|
+
async checkExists() {
|
|
142
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
143
|
+
if (webhookData.webhookId === undefined) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
147
|
+
const baseUrl = credentials.baseUrl;
|
|
148
|
+
const webhookId = webhookData.webhookId;
|
|
149
|
+
try {
|
|
150
|
+
const response = await this.helpers.request({
|
|
151
|
+
method: 'GET',
|
|
152
|
+
url: `${baseUrl}/api/v1/webhooks/${webhookId}`,
|
|
153
|
+
json: true,
|
|
154
|
+
});
|
|
155
|
+
return response.active === true;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async create() {
|
|
162
|
+
const webhookUrl = this.getNodeWebhookUrl('default');
|
|
163
|
+
const event = this.getNodeParameter('event');
|
|
164
|
+
const filters = this.getNodeParameter('filters', {});
|
|
165
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
166
|
+
const baseUrl = credentials.baseUrl;
|
|
167
|
+
const body = {
|
|
168
|
+
url: webhookUrl,
|
|
169
|
+
event,
|
|
170
|
+
active: true,
|
|
171
|
+
filters,
|
|
172
|
+
};
|
|
173
|
+
try {
|
|
174
|
+
const response = await this.helpers.request({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
url: `${baseUrl}/api/v1/webhooks`,
|
|
177
|
+
body,
|
|
178
|
+
json: true,
|
|
179
|
+
});
|
|
180
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
181
|
+
webhookData.webhookId = response.data.id;
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async delete() {
|
|
189
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
190
|
+
if (webhookData.webhookId === undefined) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
194
|
+
const baseUrl = credentials.baseUrl;
|
|
195
|
+
const webhookId = webhookData.webhookId;
|
|
196
|
+
try {
|
|
197
|
+
await this.helpers.request({
|
|
198
|
+
method: 'DELETE',
|
|
199
|
+
url: `${baseUrl}/api/v1/webhooks/${webhookId}`,
|
|
200
|
+
json: true,
|
|
201
|
+
});
|
|
202
|
+
delete webhookData.webhookId;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
async webhook() {
|
|
213
|
+
const bodyData = this.getBodyData();
|
|
214
|
+
const event = this.getNodeParameter('event');
|
|
215
|
+
const filters = this.getNodeParameter('filters', {});
|
|
216
|
+
// Validar que el evento recibido coincida con el configurado
|
|
217
|
+
const receivedEvent = bodyData.event;
|
|
218
|
+
if (receivedEvent !== event) {
|
|
219
|
+
return {
|
|
220
|
+
webhookResponse: {
|
|
221
|
+
success: false,
|
|
222
|
+
message: 'Event mismatch',
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// Aplicar filtros si existen
|
|
227
|
+
if (Object.keys(filters).length > 0) {
|
|
228
|
+
const payload = bodyData.data;
|
|
229
|
+
// Filtro por tipo de propiedad
|
|
230
|
+
if (filters.property_type && payload.property_type !== filters.property_type) {
|
|
231
|
+
return {
|
|
232
|
+
webhookResponse: {
|
|
233
|
+
success: true,
|
|
234
|
+
message: 'Filtered out by property_type',
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Filtro por precio mínimo
|
|
239
|
+
if (filters.price_min && Number(payload.price) < Number(filters.price_min)) {
|
|
240
|
+
return {
|
|
241
|
+
webhookResponse: {
|
|
242
|
+
success: true,
|
|
243
|
+
message: 'Filtered out by price_min',
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// Filtro por precio máximo
|
|
248
|
+
if (filters.price_max && Number(payload.price) > Number(filters.price_max)) {
|
|
249
|
+
return {
|
|
250
|
+
webhookResponse: {
|
|
251
|
+
success: true,
|
|
252
|
+
message: 'Filtered out by price_max',
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// Filtro por ciudad
|
|
257
|
+
if (filters.city && payload.city !== filters.city) {
|
|
258
|
+
return {
|
|
259
|
+
webhookResponse: {
|
|
260
|
+
success: true,
|
|
261
|
+
message: 'Filtered out by city',
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
workflowData: [this.helpers.returnJsonArray(bodyData)],
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.AivenceRealtyTrigger = AivenceRealtyTrigger;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-aivencerealtycrm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Nodo n8n para integrar el CRM inmobiliario AivenceRealty",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n-community-node-package",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"dist/credentials/AivenceRealtyApi.credentials.js"
|
|
40
40
|
],
|
|
41
41
|
"nodes": [
|
|
42
|
-
"dist/nodes/AivenceRealty/AivenceRealty.node.js"
|
|
42
|
+
"dist/nodes/AivenceRealty/AivenceRealty.node.js",
|
|
43
|
+
"dist/nodes/AivenceRealtyTrigger/AivenceRealtyTrigger.node.js"
|
|
43
44
|
]
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|