@contaazul/n8n-nodes-contaazul
Version:
Node para integração com a API da Conta Azul no n8n
73 lines • 2.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPersonsByFilter = getPersonsByFilter;
exports.getPersonById = getPersonById;
exports.createPerson = createPerson;
async function getPersonsByFilter() {
var _a;
const termo_busca = this.getNodeParameter('termo_busca', 0, '');
const pagina = this.getNodeParameter('pagina_pessoa', 0, 1);
const tamanho_pagina = this.getNodeParameter('tamanho_pagina_pessoa', 0, 10);
const qs = {
pagina,
tamanho_pagina,
};
if (termo_busca) {
qs.termo_busca = termo_busca;
}
const responseData = await ((_a = this.helpers.requestOAuth2) === null || _a === void 0 ? void 0 : _a.call(this, 'contaAzulOAuth2Api', {
method: 'GET',
url: 'https://api-v2.contaazul.com/v1/pessoa',
qs,
json: true,
}));
return this.helpers.returnJsonArray(responseData);
}
async function getPersonById() {
var _a;
const personId = this.getNodeParameter('personId', 0);
const responseData = await ((_a = this.helpers.requestOAuth2) === null || _a === void 0 ? void 0 : _a.call(this, 'contaAzulOAuth2Api', {
method: 'GET',
url: `https://api-v2.contaazul.com/v1/pessoa/${personId}/resumo`,
json: true,
}));
return this.helpers.returnJsonArray([responseData]);
}
async function createPerson() {
const tipoPessoa = this.getNodeParameter('tipo_pessoa', 0);
const tipoPerfilParam = this.getNodeParameter('tipo_perfil', 0);
const perfisArray = Array.isArray(tipoPerfilParam) ? tipoPerfilParam : [tipoPerfilParam];
const body = {
tipo_pessoa: tipoPessoa,
nome: this.getNodeParameter('nome', 0),
email: this.getNodeParameter('email', 0),
telefone: this.getNodeParameter('telefone', 0),
enderecos: [
{
cep: this.getNodeParameter('cep', 0),
logradouro: this.getNodeParameter('logradouro', 0),
numero: this.getNodeParameter('numero', 0),
complemento: this.getNodeParameter('complemento', 0),
bairro: this.getNodeParameter('bairro', 0),
cidade: this.getNodeParameter('cidade', 0),
estado: this.getNodeParameter('estado', 0),
pais: this.getNodeParameter('pais', 0),
},
],
perfis: perfisArray.map((perfil) => ({ tipo_perfil: perfil })),
};
if (tipoPessoa === 'FISICA') {
body.cpf = this.getNodeParameter('cpf', 0, null);
}
if (tipoPessoa === 'JURIDICA') {
body.cnpj = this.getNodeParameter('cnpj', 0, null);
}
const response = await this.helpers.requestOAuth2.call(this, 'contaAzulOAuth2Api', {
method: 'POST',
url: 'https://api-v2.contaazul.com/v1/pessoa',
body,
json: true,
});
return [{ json: response }];
}
//# sourceMappingURL=pessoas.js.map