n8n-nodes-imobzi 0.3.42 → 0.3.44

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.
@@ -2,7 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Imobzi = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
- const createFiltersProperty = (resourceName, loadOptionsMethod) => ({
5
+ const resourceEndpoint = {
6
+ lead: 'leads',
7
+ property: 'properties',
8
+ contact: 'contacts',
9
+ contrato: 'contracts',
10
+ financeiro: 'financial/accounts',
11
+ locacao: 'rentals',
12
+ documento: 'documents',
13
+ tarefa: 'tasks',
14
+ agenda: 'agendas',
15
+ evento: 'events',
16
+ integracao: 'integrations',
17
+ usuario: 'users',
18
+ account: 'account',
19
+ };
20
+ const createFiltersProperty = () => ({
6
21
  displayName: 'Filtros',
7
22
  name: 'filters',
8
23
  type: 'fixedCollection',
@@ -11,7 +26,6 @@ const createFiltersProperty = (resourceName, loadOptionsMethod) => ({
11
26
  default: {},
12
27
  displayOptions: {
13
28
  show: {
14
- resource: [resourceName],
15
29
  operation: ['getAll', 'delete'],
16
30
  },
17
31
  },
@@ -23,8 +37,7 @@ const createFiltersProperty = (resourceName, loadOptionsMethod) => ({
23
37
  {
24
38
  displayName: 'Campo',
25
39
  name: 'field',
26
- type: 'options',
27
- typeOptions: { loadOptionsMethod },
40
+ type: 'string',
28
41
  default: '',
29
42
  description: 'Campo para filtrar',
30
43
  },
@@ -58,165 +71,224 @@ const createFiltersProperty = (resourceName, loadOptionsMethod) => ({
58
71
  },
59
72
  ],
60
73
  });
74
+ const createCreateFieldsProperty = (resourceName) => ({
75
+ displayName: 'Create Fields',
76
+ name: 'createFields',
77
+ type: 'collection',
78
+ placeholder: 'Add Field',
79
+ default: {},
80
+ displayOptions: {
81
+ show: {
82
+ resource: [resourceName],
83
+ operation: ['create'],
84
+ },
85
+ },
86
+ options: [
87
+ {
88
+ displayName: 'Date',
89
+ name: 'date',
90
+ type: 'string',
91
+ default: '',
92
+ description: 'Date of the item',
93
+ },
94
+ {
95
+ displayName: 'Description',
96
+ name: 'description',
97
+ type: 'string',
98
+ default: '',
99
+ description: 'Description of the item',
100
+ },
101
+ {
102
+ displayName: 'Email',
103
+ name: 'email',
104
+ type: 'string',
105
+ placeholder: 'name@email.com',
106
+ default: '',
107
+ description: 'Email address',
108
+ },
109
+ {
110
+ displayName: 'Name',
111
+ name: 'name',
112
+ type: 'string',
113
+ default: '',
114
+ description: 'Name of the item',
115
+ },
116
+ {
117
+ displayName: 'Phone',
118
+ name: 'phone',
119
+ type: 'string',
120
+ default: '',
121
+ description: 'Phone number',
122
+ },
123
+ {
124
+ displayName: 'Title',
125
+ name: 'title',
126
+ type: 'string',
127
+ default: '',
128
+ description: 'Title of the item',
129
+ },
130
+ {
131
+ displayName: 'Value',
132
+ name: 'value',
133
+ type: 'number',
134
+ default: 0,
135
+ description: 'Value of the item',
136
+ },
137
+ ],
138
+ });
139
+ const createUpdateFieldsProperty = (resourceName) => ({
140
+ displayName: 'Update Fields',
141
+ name: 'updateFields',
142
+ type: 'collection',
143
+ placeholder: 'Add Field',
144
+ default: {},
145
+ displayOptions: {
146
+ show: {
147
+ resource: [resourceName],
148
+ operation: ['update'],
149
+ },
150
+ },
151
+ options: [
152
+ {
153
+ displayName: 'Date',
154
+ name: 'date',
155
+ type: 'string',
156
+ default: '',
157
+ description: 'Date of the item',
158
+ },
159
+ {
160
+ displayName: 'Description',
161
+ name: 'description',
162
+ type: 'string',
163
+ default: '',
164
+ description: 'Description of the item',
165
+ },
166
+ {
167
+ displayName: 'Email',
168
+ name: 'email',
169
+ type: 'string',
170
+ placeholder: 'name@email.com',
171
+ default: '',
172
+ description: 'Email address',
173
+ },
174
+ {
175
+ displayName: 'Name',
176
+ name: 'name',
177
+ type: 'string',
178
+ default: '',
179
+ description: 'Name of the item',
180
+ },
181
+ {
182
+ displayName: 'Phone',
183
+ name: 'phone',
184
+ type: 'string',
185
+ default: '',
186
+ description: 'Phone number',
187
+ },
188
+ {
189
+ displayName: 'Title',
190
+ name: 'title',
191
+ type: 'string',
192
+ default: '',
193
+ description: 'Title of the item',
194
+ },
195
+ {
196
+ displayName: 'Value',
197
+ name: 'value',
198
+ type: 'number',
199
+ default: 0,
200
+ description: 'Value of the item',
201
+ },
202
+ ],
203
+ });
61
204
  class Imobzi {
62
205
  constructor() {
63
206
  this.methods = {
64
207
  loadOptions: {
65
- async getLeadIds() {
208
+ async getLeads() {
66
209
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/leads' });
67
- return (response.data || []).map((lead) => ({
68
- name: `${lead.name} (${lead.id})`,
69
- value: lead.id
210
+ return (response.data || []).map((item) => ({
211
+ name: item.name || `ID ${item.id}`,
212
+ value: item.id,
70
213
  }));
71
214
  },
72
- async getLeadFields() {
73
- return [
74
- { name: 'Nome', value: 'name' },
75
- { name: 'Email', value: 'email' },
76
- { name: 'Telefone', value: 'phone' },
77
- ];
78
- },
79
- async getPropertyIds() {
215
+ async getProperties() {
80
216
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/properties' });
81
217
  return (response.data || []).map((item) => ({
82
- name: `${item.title || item.name || `ID ${item.id}`}`,
83
- value: item.id
218
+ name: item.title || item.titulo || `ID ${item.id}`,
219
+ value: item.id,
84
220
  }));
85
221
  },
86
- async getPropertyFields() {
87
- return [
88
- { name: 'Título', value: 'title' },
89
- { name: 'Tipo', value: 'type' },
90
- { name: 'Status', value: 'status' },
91
- { name: 'Valor', value: 'price' },
92
- { name: 'Endereço', value: 'address' },
93
- { name: 'Proprietário', value: 'owner' },
94
- { name: 'Imagens', value: 'images' },
95
- ];
96
- },
97
- async getContactIds() {
222
+ async getContacts() {
98
223
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/contacts' });
99
224
  return (response.data || []).map((item) => ({
100
- name: `${item.name || `ID ${item.id}`}`,
101
- value: item.id
225
+ name: item.name || `ID ${item.id}`,
226
+ value: item.id,
102
227
  }));
103
228
  },
104
- async getContactFields() {
105
- return [
106
- { name: 'Nome', value: 'name' },
107
- { name: 'Email', value: 'email' },
108
- { name: 'Telefone', value: 'phone' },
109
- ];
110
- },
111
- async getContratoIds() {
229
+ async getContracts() {
112
230
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/contracts' });
113
231
  return (response.data || []).map((item) => ({
114
- name: `${item.cliente || `ID ${item.id}`}`,
115
- value: item.id
232
+ name: item.client || item.cliente || `ID ${item.id}`,
233
+ value: item.id,
116
234
  }));
117
235
  },
118
- async getContratoFields() {
119
- return [
120
- { name: 'Cliente', value: 'cliente' },
121
- { name: 'Valor', value: 'valor' },
122
- { name: 'Data De Início', value: 'dataInicio' },
123
- ];
124
- },
125
- async getFinanceiroIds() {
236
+ async getFinancialAccounts() {
126
237
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/financial/accounts' });
127
238
  return (response.data || []).map((item) => ({
128
- name: `${item.descricao || `ID ${item.id}`}`,
129
- value: item.id
239
+ name: item.description || item.descricao || `ID ${item.id}`,
240
+ value: item.id,
130
241
  }));
131
242
  },
132
- async getFinanceiroFields() {
133
- return [
134
- { name: 'Descrição', value: 'descricao' },
135
- { name: 'Valor', value: 'valor' },
136
- { name: 'Data', value: 'data' },
137
- ];
138
- },
139
- async getLocacaoIds() {
243
+ async getRentals() {
140
244
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/rentals' });
141
245
  return (response.data || []).map((item) => ({
142
- name: `${item.inquilino || `ID ${item.id}`}`,
143
- value: item.id
246
+ name: item.tenant || item.inquilino || `ID ${item.id}`,
247
+ value: item.id,
144
248
  }));
145
249
  },
146
- async getLocacaoFields() {
147
- return [
148
- { name: 'Inquilino', value: 'inquilino' },
149
- { name: 'Imóvel', value: 'imovel' },
150
- { name: 'Data De Início', value: 'dataInicio' },
151
- ];
152
- },
153
- async getDocumentoIds() {
250
+ async getDocuments() {
154
251
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/documents' });
155
252
  return (response.data || []).map((item) => ({
156
- name: `${item.nomeArquivo || `ID ${item.id}`}`,
157
- value: item.id
253
+ name: item.filename || item.nomeArquivo || `ID ${item.id}`,
254
+ value: item.id,
158
255
  }));
159
256
  },
160
- async getDocumentoFields() {
161
- return [
162
- { name: 'Nome Do Arquivo', value: 'nomeArquivo' },
163
- { name: 'Conteúdo', value: 'conteudo' },
164
- ];
165
- },
166
- async getTarefaIds() {
257
+ async getTasks() {
167
258
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/tasks' });
168
259
  return (response.data || []).map((item) => ({
169
- name: `${item.titulo || `ID ${item.id}`}`,
170
- value: item.id
260
+ name: item.title || item.titulo || `ID ${item.id}`,
261
+ value: item.id,
171
262
  }));
172
263
  },
173
- async getTarefaFields() {
174
- return [
175
- { name: 'Título', value: 'titulo' },
176
- { name: 'Descrição', value: 'descricao' },
177
- { name: 'Data De Vencimento', value: 'dataVencimento' },
178
- ];
264
+ async getAgendas() {
265
+ const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/agendas' });
266
+ return (response.data || []).map((item) => ({
267
+ name: item.title || item.titulo || `ID ${item.id}`,
268
+ value: item.id,
269
+ }));
179
270
  },
180
- async getAgendaIds() {
271
+ async getEvents() {
181
272
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/events' });
182
273
  return (response.data || []).map((item) => ({
183
- name: `${item.titulo || `ID ${item.id}`}`,
184
- value: item.id
274
+ name: item.title || item.titulo || `ID ${item.id}`,
275
+ value: item.id,
185
276
  }));
186
277
  },
187
- async getAgendaFields() {
188
- return [
189
- { name: 'Título', value: 'titulo' },
190
- { name: 'Data', value: 'data' },
191
- { name: 'Descrição', value: 'descricao' },
192
- ];
193
- },
194
- async getIntegracaoIds() {
278
+ async getIntegrations() {
195
279
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/integrations' });
196
280
  return (response.data || []).map((item) => ({
197
- name: `${item.nome || `ID ${item.id}`}`,
198
- value: item.id
281
+ name: item.name || item.nome || `ID ${item.id}`,
282
+ value: item.id,
199
283
  }));
200
284
  },
201
- async getIntegracaoFields() {
202
- return [
203
- { name: 'Nome', value: 'nome' },
204
- { name: 'Tipo', value: 'tipo' },
205
- ];
206
- },
207
- async getUsuarioIds() {
285
+ async getUsers() {
208
286
  const response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', { method: 'GET', url: '/users' });
209
287
  return (response.data || []).map((item) => ({
210
- name: `${item.name || `ID ${item.id}`}`,
211
- value: item.id
288
+ name: item.name || item.nome || `ID ${item.id}`,
289
+ value: item.id,
212
290
  }));
213
291
  },
214
- async getUsuarioFields() {
215
- return [
216
- { name: 'Nome', value: 'name' },
217
- { name: 'Email', value: 'email' },
218
- ];
219
- },
220
292
  },
221
293
  };
222
294
  this.description = {
@@ -249,6 +321,7 @@ class Imobzi {
249
321
  { name: 'Contact', value: 'contact' },
250
322
  { name: 'Contrato', value: 'contrato' },
251
323
  { name: 'Documento', value: 'documento' },
324
+ { name: 'Evento', value: 'evento' },
252
325
  { name: 'Financeiro', value: 'financeiro' },
253
326
  { name: 'Imovel', value: 'property' },
254
327
  { name: 'Integracao', value: 'integracao' },
@@ -259,171 +332,263 @@ class Imobzi {
259
332
  ],
260
333
  default: 'lead',
261
334
  },
262
- createFiltersProperty('lead', 'getLeadFields'),
263
- createFiltersProperty('property', 'getPropertyFields'),
264
- createFiltersProperty('contact', 'getContactFields'),
265
- createFiltersProperty('contrato', 'getContratoFields'),
266
- createFiltersProperty('financeiro', 'getFinanceiroFields'),
267
- createFiltersProperty('locacao', 'getLocacaoFields'),
268
- createFiltersProperty('documento', 'getDocumentoFields'),
269
- createFiltersProperty('tarefa', 'getTarefaFields'),
270
- createFiltersProperty('agenda', 'getAgendaFields'),
271
- createFiltersProperty('integracao', 'getIntegracaoFields'),
272
- createFiltersProperty('usuario', 'getUsuarioFields'),
273
335
  {
274
- displayName: 'Lead ID',
275
- name: 'id',
276
- type: 'string',
277
- default: '',
278
- required: true,
279
- displayOptions: { show: { resource: ['lead'], operation: ['get', 'update', 'delete'] } },
280
- description: 'ID do lead a ser consultado, atualizado ou deletado',
336
+ displayName: 'Operation',
337
+ name: 'operation',
338
+ type: 'options',
339
+ noDataExpression: true,
340
+ options: [
341
+ { name: 'Create', value: 'create', action: 'Create a new item' },
342
+ { name: 'Delete', value: 'delete', action: 'Delete an item' },
343
+ { name: 'Get', value: 'get', action: 'Get an item by ID' },
344
+ { name: 'Get Many', value: 'getAll', action: 'Get many items' },
345
+ { name: 'Update', value: 'update', action: 'Update an item' },
346
+ ],
347
+ default: 'create',
281
348
  },
282
349
  {
283
- displayName: 'Property ID',
350
+ displayName: 'Lead Name or ID',
284
351
  name: 'id',
285
- type: 'string',
286
- default: '',
352
+ type: 'options',
353
+ typeOptions: {
354
+ loadOptionsMethod: 'getLeads',
355
+ },
287
356
  required: true,
288
- displayOptions: { show: { resource: ['property'], operation: ['get', 'update', 'delete'] } },
289
- description: 'ID do imóvel a ser consultado, atualizado ou deletado',
357
+ default: '',
358
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
359
+ displayOptions: {
360
+ show: {
361
+ operation: ['get', 'update', 'delete'],
362
+ resource: ['lead'],
363
+ },
364
+ },
290
365
  },
291
366
  {
292
- displayName: 'Contact ID',
367
+ displayName: 'Property Name or ID',
293
368
  name: 'id',
294
- type: 'string',
295
- default: '',
369
+ type: 'options',
370
+ typeOptions: {
371
+ loadOptionsMethod: 'getProperties',
372
+ },
296
373
  required: true,
297
- displayOptions: { show: { resource: ['contact'], operation: ['get', 'update', 'delete'] } },
298
- description: 'ID do contato a ser consultado, atualizado ou deletado',
374
+ default: '',
375
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
376
+ displayOptions: {
377
+ show: {
378
+ operation: ['get', 'update', 'delete'],
379
+ resource: ['property'],
380
+ },
381
+ },
299
382
  },
300
383
  {
301
- displayName: 'Contrato ID',
384
+ displayName: 'Contact Name or ID',
302
385
  name: 'id',
303
- type: 'string',
304
- default: '',
386
+ type: 'options',
387
+ typeOptions: {
388
+ loadOptionsMethod: 'getContacts',
389
+ },
305
390
  required: true,
306
- displayOptions: { show: { resource: ['contrato'], operation: ['get', 'update', 'delete'] } },
307
- description: 'ID do contrato a ser consultado, atualizado ou deletado',
391
+ default: '',
392
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
393
+ displayOptions: {
394
+ show: {
395
+ operation: ['get', 'update', 'delete'],
396
+ resource: ['contact'],
397
+ },
398
+ },
308
399
  },
309
400
  {
310
- displayName: 'Financeiro ID',
401
+ displayName: 'Contract Name or ID',
311
402
  name: 'id',
312
- type: 'string',
313
- default: '',
403
+ type: 'options',
404
+ typeOptions: {
405
+ loadOptionsMethod: 'getContracts',
406
+ },
314
407
  required: true,
315
- displayOptions: { show: { resource: ['financeiro'], operation: ['get', 'update', 'delete'] } },
316
- description: 'ID da conta financeira a ser consultada, atualizada ou deletada',
408
+ default: '',
409
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
410
+ displayOptions: {
411
+ show: {
412
+ operation: ['get', 'update', 'delete'],
413
+ resource: ['contrato'],
414
+ },
415
+ },
317
416
  },
318
417
  {
319
- displayName: 'Locacao ID',
418
+ displayName: 'Financial Account Name or ID',
320
419
  name: 'id',
321
- type: 'string',
322
- default: '',
420
+ type: 'options',
421
+ typeOptions: {
422
+ loadOptionsMethod: 'getFinancialAccounts',
423
+ },
323
424
  required: true,
324
- displayOptions: { show: { resource: ['locacao'], operation: ['get', 'update', 'delete'] } },
325
- description: 'ID da locação a ser consultada, atualizada ou deletada',
425
+ default: '',
426
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
427
+ displayOptions: {
428
+ show: {
429
+ operation: ['get', 'update', 'delete'],
430
+ resource: ['financeiro'],
431
+ },
432
+ },
326
433
  },
327
434
  {
328
- displayName: 'Documento ID',
435
+ displayName: 'Rental Name or ID',
329
436
  name: 'id',
330
- type: 'string',
331
- default: '',
437
+ type: 'options',
438
+ typeOptions: {
439
+ loadOptionsMethod: 'getRentals',
440
+ },
332
441
  required: true,
333
- displayOptions: { show: { resource: ['documento'], operation: ['get', 'update', 'delete'] } },
334
- description: 'ID do documento a ser consultado, atualizado ou deletado',
442
+ default: '',
443
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
444
+ displayOptions: {
445
+ show: {
446
+ operation: ['get', 'update', 'delete'],
447
+ resource: ['locacao'],
448
+ },
449
+ },
335
450
  },
336
451
  {
337
- displayName: 'Tarefa ID',
452
+ displayName: 'Document Name or ID',
338
453
  name: 'id',
339
- type: 'string',
340
- default: '',
454
+ type: 'options',
455
+ typeOptions: {
456
+ loadOptionsMethod: 'getDocuments',
457
+ },
341
458
  required: true,
342
- displayOptions: { show: { resource: ['tarefa'], operation: ['get', 'update', 'delete'] } },
343
- description: 'ID da tarefa a ser consultada, atualizada ou deletada',
459
+ default: '',
460
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
461
+ displayOptions: {
462
+ show: {
463
+ operation: ['get', 'update', 'delete'],
464
+ resource: ['documento'],
465
+ },
466
+ },
344
467
  },
345
468
  {
346
- displayName: 'Agenda ID',
469
+ displayName: 'Task Name or ID',
347
470
  name: 'id',
348
- type: 'string',
349
- default: '',
471
+ type: 'options',
472
+ typeOptions: {
473
+ loadOptionsMethod: 'getTasks',
474
+ },
350
475
  required: true,
351
- displayOptions: { show: { resource: ['agenda'], operation: ['get', 'update', 'delete'] } },
352
- description: 'ID do evento a ser consultado, atualizado ou deletado',
476
+ default: '',
477
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
478
+ displayOptions: {
479
+ show: {
480
+ operation: ['get', 'update', 'delete'],
481
+ resource: ['tarefa'],
482
+ },
483
+ },
353
484
  },
354
485
  {
355
- displayName: 'Integracao ID',
486
+ displayName: 'Agenda Name or ID',
356
487
  name: 'id',
357
- type: 'string',
358
- default: '',
488
+ type: 'options',
489
+ typeOptions: {
490
+ loadOptionsMethod: 'getAgendas',
491
+ },
359
492
  required: true,
360
- displayOptions: { show: { resource: ['integracao'], operation: ['get', 'update', 'delete'] } },
361
- description: 'ID da integração a ser consultada, atualizada ou deletada',
493
+ default: '',
494
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
495
+ displayOptions: {
496
+ show: {
497
+ operation: ['get', 'update', 'delete'],
498
+ resource: ['agenda'],
499
+ },
500
+ },
362
501
  },
363
502
  {
364
- displayName: 'Usuario ID',
503
+ displayName: 'Event Name or ID',
365
504
  name: 'id',
366
- type: 'string',
367
- default: '',
505
+ type: 'options',
506
+ typeOptions: {
507
+ loadOptionsMethod: 'getEvents',
508
+ },
368
509
  required: true,
369
- displayOptions: { show: { resource: ['usuario'], operation: ['get', 'update', 'delete'] } },
370
- description: 'ID do usuário/agente a ser consultado, atualizado ou deletado',
510
+ default: '',
511
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
512
+ displayOptions: {
513
+ show: {
514
+ operation: ['get', 'update', 'delete'],
515
+ resource: ['evento'],
516
+ },
517
+ },
371
518
  },
372
519
  {
373
- displayName: 'Operation',
374
- name: 'operation',
520
+ displayName: 'Integration Name or ID',
521
+ name: 'id',
375
522
  type: 'options',
376
- noDataExpression: true,
377
- displayOptions: { show: { resource: ['lead'] } },
378
- options: [
379
- { name: 'Create', value: 'create', action: 'Create a lead' },
380
- { name: 'Delete', value: 'delete', action: 'Delete a lead' },
381
- { name: 'Get', value: 'get', action: 'Get a lead' },
382
- { name: 'Get Many', value: 'getAll', action: 'Get many a lead' },
383
- { name: 'Update', value: 'update', action: 'Update a lead' },
384
- ],
385
- default: 'create',
386
- },
387
- {
388
- displayName: 'Campos',
389
- name: 'fields',
390
- type: 'fixedCollection',
391
- options: [
392
- {
393
- name: 'field',
394
- displayName: 'Field',
395
- values: [
396
- {
397
- displayName: 'Campo Name or ID',
398
- name: 'campo',
399
- type: 'options',
400
- description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
401
- typeOptions: { loadOptionsMethod: 'getLeadFields' },
402
- default: '',
403
- },
404
- {
405
- displayName: 'Valor',
406
- name: 'valor',
407
- type: 'string',
408
- default: '',
409
- },
410
- ],
523
+ typeOptions: {
524
+ loadOptionsMethod: 'getIntegrations',
525
+ },
526
+ required: true,
527
+ default: '',
528
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
529
+ displayOptions: {
530
+ show: {
531
+ operation: ['get', 'update', 'delete'],
532
+ resource: ['integracao'],
411
533
  },
412
- ],
413
- default: {},
414
- displayOptions: { show: { resource: ['lead'], operation: ['create', 'update'] } },
534
+ },
415
535
  },
416
536
  {
417
- displayName: 'Ordenar Por Name or ID',
418
- name: 'orderBy',
537
+ displayName: 'User Name or ID',
538
+ name: 'id',
419
539
  type: 'options',
540
+ typeOptions: {
541
+ loadOptionsMethod: 'getUsers',
542
+ },
543
+ required: true,
544
+ default: '',
420
545
  description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
421
- typeOptions: { loadOptionsMethod: 'getLeadFields' },
546
+ displayOptions: {
547
+ show: {
548
+ operation: ['get', 'update', 'delete'],
549
+ resource: ['usuario'],
550
+ },
551
+ },
552
+ },
553
+ createFiltersProperty(),
554
+ createCreateFieldsProperty('lead'),
555
+ createCreateFieldsProperty('property'),
556
+ createCreateFieldsProperty('contact'),
557
+ createCreateFieldsProperty('contrato'),
558
+ createCreateFieldsProperty('financeiro'),
559
+ createCreateFieldsProperty('locacao'),
560
+ createCreateFieldsProperty('documento'),
561
+ createCreateFieldsProperty('tarefa'),
562
+ createCreateFieldsProperty('agenda'),
563
+ createCreateFieldsProperty('evento'),
564
+ createCreateFieldsProperty('integracao'),
565
+ createCreateFieldsProperty('usuario'),
566
+ createUpdateFieldsProperty('lead'),
567
+ createUpdateFieldsProperty('property'),
568
+ createUpdateFieldsProperty('contact'),
569
+ createUpdateFieldsProperty('contrato'),
570
+ createUpdateFieldsProperty('financeiro'),
571
+ createUpdateFieldsProperty('locacao'),
572
+ createUpdateFieldsProperty('documento'),
573
+ createUpdateFieldsProperty('tarefa'),
574
+ createUpdateFieldsProperty('agenda'),
575
+ createUpdateFieldsProperty('evento'),
576
+ createUpdateFieldsProperty('integracao'),
577
+ createUpdateFieldsProperty('usuario'),
578
+ {
579
+ displayName: 'Order By',
580
+ name: 'orderBy',
581
+ type: 'string',
422
582
  default: '',
423
- displayOptions: { show: { resource: ['lead'], operation: ['getAll'] } },
583
+ description: 'Field to order by',
584
+ displayOptions: {
585
+ show: {
586
+ operation: ['getAll'],
587
+ },
588
+ },
424
589
  },
425
590
  {
426
- displayName: 'Limite',
591
+ displayName: 'Limit',
427
592
  name: 'limit',
428
593
  type: 'number',
429
594
  typeOptions: {
@@ -431,7 +596,11 @@ class Imobzi {
431
596
  },
432
597
  description: 'Max number of results to return',
433
598
  default: 50,
434
- displayOptions: { show: { resource: ['lead'], operation: ['getAll'] } },
599
+ displayOptions: {
600
+ show: {
601
+ operation: ['getAll'],
602
+ },
603
+ },
435
604
  },
436
605
  {
437
606
  displayName: 'Offset',
@@ -439,576 +608,12 @@ class Imobzi {
439
608
  type: 'number',
440
609
  default: 0,
441
610
  typeOptions: { minValue: 0 },
442
- displayOptions: { show: { resource: ['lead'], operation: ['getAll'] } },
443
- },
444
- {
445
- displayName: 'Use Custom Schema',
446
- name: 'useCustomSchema',
447
- type: 'boolean',
448
- default: false,
449
- description: 'Whether to allow using custom fields/schema',
450
- },
451
- {
452
- displayName: 'Operation',
453
- name: 'operation',
454
- type: 'options',
455
- noDataExpression: true,
456
- displayOptions: { show: { resource: ['contrato'] } },
457
- options: [
458
- { name: 'Create', value: 'create', description: 'Create new contract', action: 'Create new contract' },
459
- { name: 'Get', value: 'get', description: 'Get contract by ID', action: 'Get contract by ID' },
460
- { name: 'Get Many', value: 'getAll', description: 'Get many contracts', action: 'Get many contracts' },
461
- { name: 'Update', value: 'update', description: 'Update contract', action: 'Update contract' },
462
- ],
463
- default: 'create',
464
- },
465
- {
466
- displayName: 'Client Name',
467
- name: 'cliente',
468
- type: 'string',
469
- default: '',
470
- required: true,
471
- displayOptions: { show: { resource: ['contrato'], operation: ['create'] } },
472
- description: 'Client name for the contract',
473
- },
474
- {
475
- displayName: 'Value',
476
- name: 'valor',
477
- type: 'number',
478
- default: 0,
479
- displayOptions: { show: { resource: ['contrato'], operation: ['create'] } },
480
- description: 'Contract value',
481
- },
482
- {
483
- displayName: 'Start Date',
484
- name: 'dataInicio',
485
- type: 'string',
486
- default: '',
487
- displayOptions: { show: { resource: ['contrato'], operation: ['create'] } },
488
- description: 'Contract start date',
489
- },
490
- {
491
- displayName: 'Name',
492
- name: 'name',
493
- type: 'string',
494
- default: '',
495
- required: true,
611
+ description: 'Number of items to skip',
496
612
  displayOptions: {
497
613
  show: {
498
- resource: ['lead'],
499
- operation: ['create'],
614
+ operation: ['getAll'],
500
615
  },
501
616
  },
502
- description: 'Lead name',
503
- },
504
- {
505
- displayName: 'Email',
506
- name: 'email',
507
- type: 'string',
508
- placeholder: 'name@email.com',
509
- default: '',
510
- displayOptions: {
511
- show: {
512
- resource: ['lead'],
513
- operation: ['create'],
514
- },
515
- },
516
- description: 'Lead email',
517
- },
518
- {
519
- displayName: 'Phone',
520
- name: 'phone',
521
- type: 'string',
522
- default: '',
523
- displayOptions: {
524
- show: {
525
- resource: ['lead'],
526
- operation: ['create'],
527
- },
528
- },
529
- description: 'Lead phone',
530
- },
531
- {
532
- displayName: 'Operation',
533
- name: 'operation',
534
- type: 'options',
535
- noDataExpression: true,
536
- displayOptions: { show: { resource: ['property'] } },
537
- options: [
538
- { name: 'Create', value: 'create', description: 'Criar novo imovel', action: 'Criar novo imovel' },
539
- { name: 'Delete', value: 'delete', description: 'Deletar imovel', action: 'Deletar imovel' },
540
- { name: 'Get', value: 'get', description: 'Obter imovel por ID', action: 'Obter imovel por id' },
541
- { name: 'Get Many', value: 'getAll', description: 'Listar imoveis', action: 'Listar imoveis' },
542
- { name: 'Update', value: 'update', description: 'Atualizar imovel', action: 'Atualizar imovel' },
543
- ],
544
- default: 'create',
545
- },
546
- {
547
- displayName: 'Título',
548
- name: 'title',
549
- type: 'string',
550
- default: '',
551
- required: true,
552
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
553
- description: 'Título do imóvel',
554
- },
555
- {
556
- displayName: 'Tipo',
557
- name: 'type',
558
- type: 'options',
559
- options: [
560
- { name: 'Apartamento', value: 'apartment' },
561
- { name: 'Casa', value: 'house' },
562
- { name: 'Comercial', value: 'commercial' },
563
- { name: 'Outro', value: 'other' },
564
- { name: 'Terreno', value: 'land' },
565
- ],
566
- default: 'house',
567
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
568
- description: 'Tipo do imóvel',
569
- },
570
- {
571
- displayName: 'Status',
572
- name: 'status',
573
- type: 'options',
574
- options: [
575
- { name: 'Alugado', value: 'rented' },
576
- { name: 'Disponível', value: 'available' },
577
- { name: 'Outro', value: 'other' },
578
- { name: 'Pendente', value: 'pending' },
579
- { name: 'Suspenso', value: 'suspended' },
580
- { name: 'Vendido', value: 'sold' },
581
- ],
582
- default: 'available',
583
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
584
- description: 'Status do imóvel',
585
- },
586
- {
587
- displayName: 'Valor',
588
- name: 'price',
589
- type: 'number',
590
- default: 0,
591
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
592
- description: 'Valor do imóvel',
593
- },
594
- {
595
- displayName: 'Endereço',
596
- name: 'address',
597
- type: 'string',
598
- default: '',
599
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
600
- description: 'Endereço do imóvel',
601
- },
602
- {
603
- displayName: 'Proprietário',
604
- name: 'owner',
605
- type: 'string',
606
- default: '',
607
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
608
- description: 'Nome ou ID do proprietário',
609
- },
610
- {
611
- displayName: 'Imagens (URLs)',
612
- name: 'images',
613
- type: 'string',
614
- default: '',
615
- displayOptions: { show: { resource: ['property'], operation: ['create'] } },
616
- description: 'URLs das imagens separadas por vírgula',
617
- },
618
- {
619
- displayName: 'Update Fields',
620
- name: 'updateFields',
621
- type: 'collection',
622
- placeholder: 'Add Field',
623
- default: {},
624
- displayOptions: {
625
- show: {
626
- resource: ['property'],
627
- operation: ['update'],
628
- },
629
- },
630
- options: [
631
- {
632
- displayName: 'Endereço',
633
- name: 'address',
634
- type: 'string',
635
- default: '',
636
- description: 'Endereço do imóvel',
637
- },
638
- {
639
- displayName: 'Imagens (URLs)',
640
- name: 'images',
641
- type: 'string',
642
- default: '',
643
- description: 'URLs das imagens separadas por vírgula',
644
- },
645
- {
646
- displayName: 'Proprietário',
647
- name: 'owner',
648
- type: 'string',
649
- default: '',
650
- description: 'Nome ou ID do proprietário',
651
- },
652
- {
653
- displayName: 'Status',
654
- name: 'status',
655
- type: 'options',
656
- options: [
657
- { name: 'Alugado', value: 'rented' },
658
- { name: 'Disponível', value: 'available' },
659
- { name: 'Outro', value: 'other' },
660
- { name: 'Pendente', value: 'pending' },
661
- { name: 'Suspenso', value: 'suspended' },
662
- { name: 'Vendido', value: 'sold' },
663
- ],
664
- default: 'available',
665
- description: 'Status do imóvel',
666
- },
667
- {
668
- displayName: 'Tipo',
669
- name: 'type',
670
- type: 'options',
671
- options: [
672
- { name: 'Apartamento', value: 'apartment' },
673
- { name: 'Casa', value: 'house' },
674
- { name: 'Comercial', value: 'commercial' },
675
- { name: 'Outro', value: 'other' },
676
- { name: 'Terreno', value: 'land' },
677
- ],
678
- default: 'house',
679
- description: 'Tipo do imóvel',
680
- },
681
- {
682
- displayName: 'Título',
683
- name: 'title',
684
- type: 'string',
685
- default: '',
686
- description: 'Título do imóvel',
687
- },
688
- {
689
- displayName: 'Valor',
690
- name: 'price',
691
- type: 'number',
692
- default: 0,
693
- description: 'Valor do imóvel',
694
- },
695
- ],
696
- },
697
- {
698
- displayName: 'Ordenar Por Name or ID',
699
- name: 'orderBy',
700
- type: 'options',
701
- description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
702
- typeOptions: { loadOptionsMethod: 'getPropertyFields' },
703
- default: '',
704
- displayOptions: { show: { resource: ['property'], operation: ['getAll'] } },
705
- },
706
- {
707
- displayName: 'Limite',
708
- name: 'limit',
709
- type: 'number',
710
- typeOptions: {
711
- minValue: 1,
712
- },
713
- description: 'Max number of results to return',
714
- default: 50,
715
- displayOptions: { show: { resource: ['property'], operation: ['getAll'] } },
716
- },
717
- {
718
- displayName: 'Offset',
719
- name: 'offset',
720
- type: 'number',
721
- default: 0,
722
- typeOptions: { minValue: 0 },
723
- displayOptions: { show: { resource: ['property'], operation: ['getAll'] } },
724
- },
725
- {
726
- displayName: 'Name',
727
- name: 'contactName',
728
- type: 'string',
729
- default: '',
730
- required: true,
731
- displayOptions: {
732
- show: {
733
- resource: ['contact'],
734
- operation: ['create'],
735
- },
736
- },
737
- description: 'Contact name',
738
- },
739
- {
740
- displayName: 'Email',
741
- name: 'contactEmail',
742
- type: 'string',
743
- default: '',
744
- displayOptions: {
745
- show: {
746
- resource: ['contact'],
747
- operation: ['create'],
748
- },
749
- },
750
- description: 'Contact email',
751
- },
752
- {
753
- displayName: 'Phone',
754
- name: 'contactPhone',
755
- type: 'string',
756
- default: '',
757
- displayOptions: {
758
- show: {
759
- resource: ['contact'],
760
- operation: ['create'],
761
- },
762
- },
763
- description: 'Contact phone',
764
- },
765
- {
766
- displayName: 'Operation',
767
- name: 'operation',
768
- type: 'options',
769
- noDataExpression: true,
770
- displayOptions: { show: { resource: ['financeiro'] } },
771
- options: [
772
- { name: 'Create', value: 'create', description: 'Create new entry', action: 'Create new entry' },
773
- { name: 'Get', value: 'get', description: 'Get entry by ID', action: 'Get entry by ID' },
774
- { name: 'Get Many', value: 'getAll', description: 'Get many entries', action: 'Get many entries' },
775
- { name: 'Update', value: 'update', description: 'Update entry', action: 'Update entry' },
776
- ],
777
- default: 'create',
778
- },
779
- {
780
- displayName: 'Description',
781
- name: 'descricao',
782
- type: 'string',
783
- default: '',
784
- required: true,
785
- displayOptions: { show: { resource: ['financeiro'], operation: ['create'] } },
786
- description: 'Entry description',
787
- },
788
- {
789
- displayName: 'Value',
790
- name: 'valor',
791
- type: 'number',
792
- default: 0,
793
- displayOptions: { show: { resource: ['financeiro'], operation: ['create'] } },
794
- description: 'Entry value',
795
- },
796
- {
797
- displayName: 'Date',
798
- name: 'data',
799
- type: 'string',
800
- default: '',
801
- displayOptions: { show: { resource: ['financeiro'], operation: ['create'] } },
802
- description: 'Entry date',
803
- },
804
- {
805
- displayName: 'Operation',
806
- name: 'operation',
807
- type: 'options',
808
- noDataExpression: true,
809
- displayOptions: { show: { resource: ['locacao'] } },
810
- options: [
811
- { name: 'Create', value: 'create', description: 'Create new rental', action: 'Create new rental' },
812
- { name: 'Get', value: 'get', description: 'Get rental by ID', action: 'Get rental by ID' },
813
- { name: 'Get Many', value: 'getAll', description: 'Get many rentals', action: 'Get many rentals' },
814
- { name: 'Update', value: 'update', description: 'Update rental', action: 'Update rental' },
815
- ],
816
- default: 'create',
817
- },
818
- {
819
- displayName: 'Tenant Name',
820
- name: 'inquilino',
821
- type: 'string',
822
- default: '',
823
- required: true,
824
- displayOptions: { show: { resource: ['locacao'], operation: ['create'] } },
825
- },
826
- {
827
- displayName: 'Property',
828
- name: 'imovel',
829
- type: 'string',
830
- default: '',
831
- displayOptions: { show: { resource: ['locacao'], operation: ['create'] } },
832
- description: 'Rented property ID',
833
- },
834
- {
835
- displayName: 'Start Date',
836
- name: 'dataInicio',
837
- type: 'string',
838
- default: '',
839
- displayOptions: { show: { resource: ['locacao'], operation: ['create'] } },
840
- description: 'Rental start date',
841
- },
842
- {
843
- displayName: 'Operation',
844
- name: 'operation',
845
- type: 'options',
846
- noDataExpression: true,
847
- displayOptions: { show: { resource: ['documento'] } },
848
- options: [
849
- { name: 'Create', value: 'create', description: 'Upload document', action: 'Upload document' },
850
- { name: 'Get', value: 'get', description: 'Get document by ID', action: 'Get document by ID' },
851
- { name: 'Get Many', value: 'getAll', description: 'Get many documents', action: 'Get many documents' },
852
- { name: 'Update', value: 'update', description: 'Update document', action: 'Update document' },
853
- ],
854
- default: 'create',
855
- },
856
- {
857
- displayName: 'File Name',
858
- name: 'nomeArquivo',
859
- type: 'string',
860
- default: '',
861
- required: true,
862
- displayOptions: { show: { resource: ['documento'], operation: ['create'] } },
863
- description: 'Name of the file to upload',
864
- },
865
- {
866
- displayName: 'Content (Base64)',
867
- name: 'conteudo',
868
- type: 'string',
869
- default: '',
870
- displayOptions: { show: { resource: ['documento'], operation: ['create'] } },
871
- description: 'File content in base64',
872
- },
873
- {
874
- displayName: 'Operation',
875
- name: 'operation',
876
- type: 'options',
877
- noDataExpression: true,
878
- displayOptions: { show: { resource: ['tarefa'] } },
879
- options: [
880
- { name: 'Create', value: 'create', description: 'Create new task', action: 'Create new task' },
881
- { name: 'Get', value: 'get', description: 'Get task by ID', action: 'Get task by ID' },
882
- { name: 'Get Many', value: 'getAll', description: 'Get many tasks', action: 'Get many tasks' },
883
- { name: 'Update', value: 'update', description: 'Update task', action: 'Update task' },
884
- ],
885
- default: 'create',
886
- },
887
- {
888
- displayName: 'Title',
889
- name: 'titulo',
890
- type: 'string',
891
- default: '',
892
- required: true,
893
- displayOptions: { show: { resource: ['tarefa'], operation: ['create'] } },
894
- description: 'Task title',
895
- },
896
- {
897
- displayName: 'Description',
898
- name: 'descricao',
899
- type: 'string',
900
- default: '',
901
- displayOptions: { show: { resource: ['tarefa'], operation: ['create'] } },
902
- description: 'Task description',
903
- },
904
- {
905
- displayName: 'Due Date',
906
- name: 'dataVencimento',
907
- type: 'string',
908
- default: '',
909
- displayOptions: { show: { resource: ['tarefa'], operation: ['create'] } },
910
- description: 'Task due date',
911
- },
912
- {
913
- displayName: 'Operation',
914
- name: 'operation',
915
- type: 'options',
916
- noDataExpression: true,
917
- displayOptions: { show: { resource: ['agenda'] } },
918
- options: [
919
- { name: 'Create', value: 'create', description: 'Create new event', action: 'Create new event' },
920
- { name: 'Get', value: 'get', description: 'Get event by ID', action: 'Get event by ID' },
921
- { name: 'Get Many', value: 'getAll', description: 'Get many events', action: 'Get many events' },
922
- { name: 'Update', value: 'update', description: 'Update event', action: 'Update event' },
923
- ],
924
- default: 'create',
925
- },
926
- {
927
- displayName: 'Title',
928
- name: 'titulo',
929
- type: 'string',
930
- default: '',
931
- required: true,
932
- displayOptions: { show: { resource: ['agenda'], operation: ['create'] } },
933
- description: 'Event title',
934
- },
935
- {
936
- displayName: 'Date',
937
- name: 'data',
938
- type: 'string',
939
- default: '',
940
- displayOptions: { show: { resource: ['agenda'], operation: ['create'] } },
941
- description: 'Event date',
942
- },
943
- {
944
- displayName: 'Description',
945
- name: 'descricao',
946
- type: 'string',
947
- default: '',
948
- displayOptions: { show: { resource: ['agenda'], operation: ['create'] } },
949
- description: 'Event description',
950
- },
951
- {
952
- displayName: 'Operation',
953
- name: 'operation',
954
- type: 'options',
955
- noDataExpression: true,
956
- displayOptions: { show: { resource: ['integracao'] } },
957
- options: [
958
- { name: 'Create', value: 'create', description: 'Create new integration', action: 'Create new integration' },
959
- { name: 'Get', value: 'get', description: 'Get integration by ID', action: 'Get integration by ID' },
960
- { name: 'Get Many', value: 'getAll', description: 'Get many integrations', action: 'Get many integrations' },
961
- { name: 'Update', value: 'update', description: 'Update integration', action: 'Update integration' },
962
- ],
963
- default: 'create',
964
- },
965
- {
966
- displayName: 'Integration Name',
967
- name: 'nome',
968
- type: 'string',
969
- default: '',
970
- required: true,
971
- displayOptions: { show: { resource: ['integracao'], operation: ['create'] } },
972
- },
973
- {
974
- displayName: 'Type',
975
- name: 'tipo',
976
- type: 'string',
977
- default: '',
978
- displayOptions: { show: { resource: ['integracao'], operation: ['create'] } },
979
- description: 'Integration type',
980
- },
981
- {
982
- displayName: 'Operation',
983
- name: 'operation',
984
- type: 'options',
985
- noDataExpression: true,
986
- displayOptions: { show: { resource: ['usuario'] } },
987
- options: [
988
- { name: 'Create', value: 'create', description: 'Create new user/agent', action: 'Create new user agent' },
989
- { name: 'Get', value: 'get', description: 'Get user/agent by ID', action: 'Get user agent by id' },
990
- { name: 'Get Many', value: 'getAll', description: 'Get many users/agents', action: 'Get many users agents' },
991
- { name: 'Update', value: 'update', description: 'Update user/agent', action: 'Update user agent' },
992
- ],
993
- default: 'create',
994
- },
995
- {
996
- displayName: 'Name',
997
- name: 'nome',
998
- type: 'string',
999
- default: '',
1000
- required: true,
1001
- displayOptions: { show: { resource: ['usuario'], operation: ['create'] } },
1002
- description: 'User/Agent name',
1003
- },
1004
- {
1005
- displayName: 'Email',
1006
- name: 'email',
1007
- type: 'string',
1008
- placeholder: 'name@email.com',
1009
- default: '',
1010
- displayOptions: { show: { resource: ['usuario'], operation: ['create'] } },
1011
- description: 'User/Agent email',
1012
617
  },
1013
618
  ],
1014
619
  };
@@ -1016,395 +621,86 @@ class Imobzi {
1016
621
  async execute() {
1017
622
  const items = this.getInputData();
1018
623
  const returnData = [];
1019
- const resource = this.getNodeParameter('resource', 0);
1020
- const operation = this.getNodeParameter('operation', 0);
1021
- const credentials = await this.getCredentials('imobziApi');
1022
- const apiUrl = 'https://api.imobzi.app/v1';
1023
- const processFilters = (filters) => {
1024
- const processedFilters = {};
624
+ const buildQueryFromFilters = (filters) => {
625
+ const query = {};
1025
626
  if (filters && filters.filter && Array.isArray(filters.filter)) {
1026
627
  filters.filter.forEach((filter) => {
1027
628
  if (filter.field && filter.operator && filter.value !== undefined) {
1028
- const fieldName = filter.field;
1029
- const operator = filter.operator;
1030
- const value = filter.value;
1031
- const filterKey = `${fieldName}_${operator}`;
1032
- processedFilters[filterKey] = value;
629
+ const filterKey = `${filter.field}_${filter.operator}`;
630
+ query[filterKey] = filter.value;
1033
631
  }
1034
632
  });
1035
633
  }
1036
- return processedFilters;
634
+ return query;
1037
635
  };
1038
636
  for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
1039
637
  try {
1040
- let response;
1041
- let method = 'GET';
1042
- let endpoint = '';
1043
- let body = {};
1044
- let qs = {};
1045
- if (['get', 'getAll', 'delete'].includes(operation)) {
1046
- const filters = this.getNodeParameter('filters', itemIndex);
1047
- const processedFilters = processFilters(filters);
1048
- if (Object.keys(processedFilters).length > 0) {
1049
- qs = { ...qs, ...processedFilters };
1050
- }
1051
- }
1052
- if (resource === 'lead') {
1053
- if (operation === 'create') {
1054
- method = 'POST';
1055
- endpoint = '/leads';
1056
- body = {
1057
- name: this.getNodeParameter('name', itemIndex),
1058
- email: this.getNodeParameter('email', itemIndex),
1059
- phone: this.getNodeParameter('phone', itemIndex),
1060
- };
1061
- }
1062
- else if (operation === 'get') {
1063
- method = 'GET';
1064
- endpoint = `/lead/${this.getNodeParameter('id', itemIndex)}`;
1065
- }
1066
- else if (operation === 'getAll') {
1067
- method = 'GET';
1068
- endpoint = '/leads';
1069
- const orderBy = this.getNodeParameter('orderBy', itemIndex);
1070
- const limit = this.getNodeParameter('limit', itemIndex);
1071
- const offset = this.getNodeParameter('offset', itemIndex);
1072
- if (orderBy) {
1073
- qs.orderBy = orderBy;
1074
- }
1075
- if (limit) {
1076
- qs.limit = limit;
1077
- }
1078
- if (offset) {
1079
- qs.offset = offset;
1080
- }
1081
- }
1082
- else if (operation === 'update') {
1083
- method = 'PUT';
1084
- endpoint = `/lead/${this.getNodeParameter('id', itemIndex)}`;
1085
- body = {
1086
- name: this.getNodeParameter('name', itemIndex),
1087
- email: this.getNodeParameter('email', itemIndex),
1088
- phone: this.getNodeParameter('phone', itemIndex),
1089
- };
1090
- }
1091
- else if (operation === 'delete') {
1092
- method = 'DELETE';
1093
- endpoint = `/lead/${this.getNodeParameter('id', itemIndex)}`;
1094
- }
638
+ const resource = this.getNodeParameter('resource', itemIndex);
639
+ const operation = this.getNodeParameter('operation', itemIndex);
640
+ const endpoint = resourceEndpoint[resource];
641
+ if (!endpoint) {
642
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Recurso "${resource}" não suportado!`);
1095
643
  }
1096
- else if (resource === 'property') {
1097
- if (operation === 'create') {
1098
- method = 'POST';
1099
- endpoint = '/properties';
1100
- const imagesParam = this.getNodeParameter('images', itemIndex);
1101
- body = {
1102
- title: this.getNodeParameter('title', itemIndex),
1103
- type: this.getNodeParameter('type', itemIndex),
1104
- status: this.getNodeParameter('status', itemIndex),
1105
- price: this.getNodeParameter('price', itemIndex),
1106
- address: this.getNodeParameter('address', itemIndex),
1107
- owner: this.getNodeParameter('owner', itemIndex),
1108
- images: typeof imagesParam === 'string' ? imagesParam.split(',').map((i) => i.trim()).filter(Boolean) : [],
1109
- };
1110
- }
1111
- else if (operation === 'get') {
1112
- method = 'GET';
1113
- endpoint = `/property/${this.getNodeParameter('id', itemIndex)}`;
1114
- }
1115
- else if (operation === 'getAll') {
1116
- method = 'GET';
1117
- endpoint = '/properties';
644
+ let response;
645
+ switch (operation) {
646
+ case 'getAll': {
647
+ const filters = this.getNodeParameter('filters', itemIndex, {});
1118
648
  const orderBy = this.getNodeParameter('orderBy', itemIndex);
1119
649
  const limit = this.getNodeParameter('limit', itemIndex);
1120
650
  const offset = this.getNodeParameter('offset', itemIndex);
1121
- if (orderBy) {
651
+ const qs = buildQueryFromFilters(filters);
652
+ if (orderBy)
1122
653
  qs.orderBy = orderBy;
1123
- }
1124
- if (limit) {
654
+ if (limit)
1125
655
  qs.limit = limit;
1126
- }
1127
- if (offset) {
656
+ if (offset)
1128
657
  qs.offset = offset;
1129
- }
1130
- }
1131
- else if (operation === 'update') {
1132
- method = 'PUT';
1133
- endpoint = `/property/${this.getNodeParameter('id', itemIndex)}`;
1134
- const updateFields = this.getNodeParameter('updateFields', itemIndex);
1135
- if (updateFields && Object.keys(updateFields).length > 0) {
1136
- body = { ...updateFields };
1137
- if (updateFields.images && typeof updateFields.images === 'string') {
1138
- body.images = updateFields.images.split(',').map((i) => i.trim()).filter(Boolean);
1139
- }
1140
- }
1141
- }
1142
- else if (operation === 'delete') {
1143
- method = 'DELETE';
1144
- endpoint = `/property/${this.getNodeParameter('id', itemIndex)}`;
1145
- }
1146
- }
1147
- else if (resource === 'contact') {
1148
- if (operation === 'create') {
1149
- method = 'POST';
1150
- endpoint = '/contacts';
1151
- body = {
1152
- name: this.getNodeParameter('contactName', itemIndex),
1153
- email: this.getNodeParameter('contactEmail', itemIndex),
1154
- phone: this.getNodeParameter('contactPhone', itemIndex),
1155
- };
1156
- }
1157
- else if (operation === 'get') {
1158
- method = 'GET';
1159
- endpoint = `/contact/${this.getNodeParameter('id', itemIndex)}`;
1160
- }
1161
- else if (operation === 'getAll') {
1162
- method = 'GET';
1163
- endpoint = '/contacts';
1164
- }
1165
- else if (operation === 'update') {
1166
- method = 'PUT';
1167
- endpoint = `/contact/${this.getNodeParameter('id', itemIndex)}`;
1168
- body = {
1169
- name: this.getNodeParameter('contactName', itemIndex),
1170
- email: this.getNodeParameter('contactEmail', itemIndex),
1171
- phone: this.getNodeParameter('contactPhone', itemIndex),
1172
- };
1173
- }
658
+ response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', {
659
+ method: 'GET',
660
+ url: `/${endpoint}`,
661
+ qs: Object.keys(qs).length > 0 ? qs : undefined,
662
+ });
663
+ break;
664
+ }
665
+ case 'get': {
666
+ const id = this.getNodeParameter('id', itemIndex);
667
+ response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', {
668
+ method: 'GET',
669
+ url: `/${endpoint}/${id}`,
670
+ });
671
+ break;
672
+ }
673
+ case 'create': {
674
+ const body = this.getNodeParameter('createFields', itemIndex);
675
+ response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', {
676
+ method: 'POST',
677
+ url: `/${endpoint}`,
678
+ body: Object.keys(body).length > 0 ? body : undefined,
679
+ });
680
+ break;
681
+ }
682
+ case 'update': {
683
+ const id = this.getNodeParameter('id', itemIndex);
684
+ const body = this.getNodeParameter('updateFields', itemIndex);
685
+ response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', {
686
+ method: 'PUT',
687
+ url: `/${endpoint}/${id}`,
688
+ body: Object.keys(body).length > 0 ? body : undefined,
689
+ });
690
+ break;
691
+ }
692
+ case 'delete': {
693
+ const id = this.getNodeParameter('id', itemIndex);
694
+ response = await this.helpers.requestWithAuthentication.call(this, 'imobziApi', {
695
+ method: 'DELETE',
696
+ url: `/${endpoint}/${id}`,
697
+ });
698
+ break;
699
+ }
700
+ default:
701
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operação "${operation}" não suportada!`);
1174
702
  }
1175
- else if (resource === 'contrato') {
1176
- if (operation === 'create') {
1177
- method = 'POST';
1178
- endpoint = '/contracts';
1179
- body = {
1180
- cliente: this.getNodeParameter('cliente', itemIndex),
1181
- valor: this.getNodeParameter('valor', itemIndex),
1182
- dataInicio: this.getNodeParameter('dataInicio', itemIndex),
1183
- };
1184
- }
1185
- else if (operation === 'get') {
1186
- method = 'GET';
1187
- endpoint = `/contract/${this.getNodeParameter('id', itemIndex)}`;
1188
- }
1189
- else if (operation === 'getAll') {
1190
- method = 'GET';
1191
- endpoint = '/contracts';
1192
- }
1193
- else if (operation === 'update') {
1194
- method = 'PUT';
1195
- endpoint = `/contract/${this.getNodeParameter('id', itemIndex)}`;
1196
- body = {
1197
- cliente: this.getNodeParameter('cliente', itemIndex),
1198
- valor: this.getNodeParameter('valor', itemIndex),
1199
- dataInicio: this.getNodeParameter('dataInicio', itemIndex),
1200
- };
1201
- }
1202
- }
1203
- else if (resource === 'financeiro') {
1204
- if (operation === 'create') {
1205
- method = 'POST';
1206
- endpoint = '/financial/accounts';
1207
- body = {
1208
- descricao: this.getNodeParameter('descricao', itemIndex),
1209
- valor: this.getNodeParameter('valor', itemIndex),
1210
- data: this.getNodeParameter('data', itemIndex),
1211
- };
1212
- }
1213
- else if (operation === 'get') {
1214
- method = 'GET';
1215
- endpoint = `/financial/account/${this.getNodeParameter('id', itemIndex)}`;
1216
- }
1217
- else if (operation === 'getAll') {
1218
- method = 'GET';
1219
- endpoint = '/financial/accounts';
1220
- }
1221
- else if (operation === 'update') {
1222
- method = 'PUT';
1223
- endpoint = `/financial/account/${this.getNodeParameter('id', itemIndex)}`;
1224
- body = {
1225
- descricao: this.getNodeParameter('descricao', itemIndex),
1226
- valor: this.getNodeParameter('valor', itemIndex),
1227
- data: this.getNodeParameter('data', itemIndex),
1228
- };
1229
- }
1230
- }
1231
- else if (resource === 'locacao') {
1232
- if (operation === 'create') {
1233
- method = 'POST';
1234
- endpoint = '/rentals';
1235
- body = {
1236
- inquilino: this.getNodeParameter('inquilino', itemIndex),
1237
- imovel: this.getNodeParameter('imovel', itemIndex),
1238
- dataInicio: this.getNodeParameter('dataInicio', itemIndex),
1239
- };
1240
- }
1241
- else if (operation === 'get') {
1242
- method = 'GET';
1243
- endpoint = `/rental/${this.getNodeParameter('id', itemIndex)}`;
1244
- }
1245
- else if (operation === 'getAll') {
1246
- method = 'GET';
1247
- endpoint = '/rentals';
1248
- }
1249
- else if (operation === 'update') {
1250
- method = 'PUT';
1251
- endpoint = `/rental/${this.getNodeParameter('id', itemIndex)}`;
1252
- body = {
1253
- inquilino: this.getNodeParameter('inquilino', itemIndex),
1254
- imovel: this.getNodeParameter('imovel', itemIndex),
1255
- dataInicio: this.getNodeParameter('dataInicio', itemIndex),
1256
- };
1257
- }
1258
- }
1259
- else if (resource === 'documento') {
1260
- if (operation === 'create') {
1261
- method = 'POST';
1262
- endpoint = '/documents';
1263
- body = {
1264
- nomeArquivo: this.getNodeParameter('nomeArquivo', itemIndex),
1265
- conteudo: this.getNodeParameter('conteudo', itemIndex),
1266
- };
1267
- }
1268
- else if (operation === 'get') {
1269
- method = 'GET';
1270
- endpoint = `/document/${this.getNodeParameter('id', itemIndex)}`;
1271
- }
1272
- else if (operation === 'getAll') {
1273
- method = 'GET';
1274
- endpoint = '/documents';
1275
- }
1276
- else if (operation === 'update') {
1277
- method = 'PUT';
1278
- endpoint = `/document/${this.getNodeParameter('id', itemIndex)}`;
1279
- body = {
1280
- nomeArquivo: this.getNodeParameter('nomeArquivo', itemIndex),
1281
- conteudo: this.getNodeParameter('conteudo', itemIndex),
1282
- };
1283
- }
1284
- }
1285
- else if (resource === 'tarefa') {
1286
- if (operation === 'create') {
1287
- method = 'POST';
1288
- endpoint = '/tasks';
1289
- body = {
1290
- titulo: this.getNodeParameter('titulo', itemIndex),
1291
- descricao: this.getNodeParameter('descricao', itemIndex),
1292
- dataVencimento: this.getNodeParameter('dataVencimento', itemIndex),
1293
- };
1294
- }
1295
- else if (operation === 'get') {
1296
- method = 'GET';
1297
- endpoint = `/task/${this.getNodeParameter('id', itemIndex)}`;
1298
- }
1299
- else if (operation === 'getAll') {
1300
- method = 'GET';
1301
- endpoint = '/tasks';
1302
- }
1303
- else if (operation === 'update') {
1304
- method = 'PUT';
1305
- endpoint = `/task/${this.getNodeParameter('id', itemIndex)}`;
1306
- body = {
1307
- titulo: this.getNodeParameter('titulo', itemIndex),
1308
- descricao: this.getNodeParameter('descricao', itemIndex),
1309
- dataVencimento: this.getNodeParameter('dataVencimento', itemIndex),
1310
- };
1311
- }
1312
- }
1313
- else if (resource === 'agenda') {
1314
- if (operation === 'create') {
1315
- method = 'POST';
1316
- endpoint = '/events';
1317
- body = {
1318
- titulo: this.getNodeParameter('titulo', itemIndex),
1319
- data: this.getNodeParameter('data', itemIndex),
1320
- descricao: this.getNodeParameter('descricao', itemIndex),
1321
- };
1322
- }
1323
- else if (operation === 'get') {
1324
- method = 'GET';
1325
- endpoint = `/events/${this.getNodeParameter('id', itemIndex)}`;
1326
- }
1327
- else if (operation === 'getAll') {
1328
- method = 'GET';
1329
- endpoint = '/events';
1330
- }
1331
- else if (operation === 'update') {
1332
- method = 'PUT';
1333
- endpoint = `/events/${this.getNodeParameter('id', itemIndex)}`;
1334
- body = {
1335
- titulo: this.getNodeParameter('titulo', itemIndex),
1336
- data: this.getNodeParameter('data', itemIndex),
1337
- descricao: this.getNodeParameter('descricao', itemIndex),
1338
- };
1339
- }
1340
- }
1341
- else if (resource === 'integracao') {
1342
- if (operation === 'create') {
1343
- method = 'POST';
1344
- endpoint = '/integrations';
1345
- body = {
1346
- nome: this.getNodeParameter('nome', itemIndex),
1347
- tipo: this.getNodeParameter('tipo', itemIndex),
1348
- };
1349
- }
1350
- else if (operation === 'get') {
1351
- method = 'GET';
1352
- endpoint = `/integrations/${this.getNodeParameter('id', itemIndex)}`;
1353
- }
1354
- else if (operation === 'getAll') {
1355
- method = 'GET';
1356
- endpoint = '/integrations';
1357
- }
1358
- else if (operation === 'update') {
1359
- method = 'PUT';
1360
- endpoint = `/integrations/${this.getNodeParameter('id', itemIndex)}`;
1361
- body = {
1362
- nome: this.getNodeParameter('nome', itemIndex),
1363
- tipo: this.getNodeParameter('tipo', itemIndex),
1364
- };
1365
- }
1366
- }
1367
- else if (resource === 'usuario') {
1368
- if (operation === 'create') {
1369
- method = 'POST';
1370
- endpoint = '/users';
1371
- body = {
1372
- name: this.getNodeParameter('name', itemIndex),
1373
- email: this.getNodeParameter('email', itemIndex),
1374
- };
1375
- }
1376
- else if (operation === 'get') {
1377
- method = 'GET';
1378
- endpoint = `/users/${this.getNodeParameter('id', itemIndex)}`;
1379
- }
1380
- else if (operation === 'getAll') {
1381
- method = 'GET';
1382
- endpoint = '/users';
1383
- }
1384
- else if (operation === 'update') {
1385
- method = 'PUT';
1386
- endpoint = `/users/${this.getNodeParameter('id', itemIndex)}`;
1387
- body = {
1388
- name: this.getNodeParameter('name', itemIndex),
1389
- email: this.getNodeParameter('email', itemIndex),
1390
- };
1391
- }
1392
- }
1393
- else if (resource === 'account') {
1394
- method = 'GET';
1395
- endpoint = '/account';
1396
- }
1397
- response = await this.helpers.httpRequest.call(this, {
1398
- method,
1399
- url: `${apiUrl}${endpoint}`,
1400
- headers: {
1401
- 'X-Imobzi-Secret': credentials.apiKey,
1402
- },
1403
- body: Object.keys(body).length ? body : undefined,
1404
- qs: Object.keys(qs).length ? qs : undefined,
1405
- json: true,
1406
- });
1407
- returnData.push({ json: response });
703
+ returnData.push({ json: response.data || response });
1408
704
  }
1409
705
  catch (error) {
1410
706
  if (this.continueOnFail()) {