n8n-nodes-imobzi 0.3.41 → 0.3.43

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