UNPKG

@contaazul/n8n-nodes-contaazul

Version:

Node for integration with Conta Azul API in n8n

80 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllServices = getAllServices; exports.getServiceById = getServiceById; exports.createService = createService; async function getAllServices() { const busca_textual = this.getNodeParameter('serviceAdditionalFields.busca_textual', 0, ''); const pagina = this.getNodeParameter('serviceAdditionalFields.pagina', 0, 1); const tamanho_pagina = this.getNodeParameter('serviceAdditionalFields.tamanho_pagina', 0, 10); const qs = { pagina, tamanho_pagina, }; if (busca_textual) { qs.busca_textual = busca_textual; } const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'contaAzulOAuth2Api', { method: 'GET', url: 'https://api-v2.contaazul.com/v1/servicos', qs, json: true, }); const items = (responseData.itens || []).map((item) => ({ json: item, pairedItem: { item: 0, }, })); return items; } async function getServiceById() { const serviceId = this.getNodeParameter('serviceId', 0); const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'contaAzulOAuth2Api', { method: 'GET', url: `https://api-v2.contaazul.com/v1/servicos/${serviceId}`, json: true, }); return [ { json: responseData, pairedItem: { item: 0, }, }, ]; } async function createService() { const descricao = this.getNodeParameter('descricao', 0); const body = { descricao, }; const codigo = this.getNodeParameter('serviceCreateAdditionalFields.codigo', 0, ''); if (codigo) { body.codigo = codigo; } const custo = this.getNodeParameter('serviceCreateAdditionalFields.custo', 0, 0); if (custo) { body.custo = custo; } const preco = this.getNodeParameter('serviceCreateAdditionalFields.preco', 0, 0); if (preco) { body.preco = preco; } const status = this.getNodeParameter('serviceCreateAdditionalFields.status', 0, 'ATIVO'); if (status) { body.status = status; } const tipo_servico = this.getNodeParameter('serviceCreateAdditionalFields.tipo_servico', 0, 'PRESTADO'); if (tipo_servico) { body.tipo_servico = tipo_servico; } const response = await this.helpers.httpRequestWithAuthentication.call(this, 'contaAzulOAuth2Api', { method: 'POST', url: 'https://api-v2.contaazul.com/v1/servicos', body, json: true, }); return [{ json: response }]; } //# sourceMappingURL=servicos.js.map