@contaazul/n8n-nodes-contaazul
Version:
Node para integração com a API da Conta Azul no n8n
59 lines • 2.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProductsByFilter = getProductsByFilter;
exports.createProduct = createProduct;
async function getProductsByFilter() {
var _a;
const busca = this.getNodeParameter('busca_produto', 0, '');
const status = this.getNodeParameter('status_produto', 0, 'TODOS');
const campo_ordenacao = this.getNodeParameter('campo_ordenacao', 0, 'NOME');
const direcao_ordenacao = this.getNodeParameter('direcao_ordenacao', 0, 'ASC');
const pagina = this.getNodeParameter('pagina_produto', 0, 1);
const tamanho_pagina = this.getNodeParameter('tamanho_pagina_produto', 0, 10);
const qs = {
pagina,
tamanho_pagina,
status,
campo_ordenacao,
direcao_ordenacao,
};
if (busca) {
qs.busca = 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/produto/busca',
qs,
json: true,
}));
return this.helpers.returnJsonArray(responseData.itens);
}
async function createProduct() {
const body = {
nome: this.getNodeParameter('nome', 0),
codigo_sku: this.getNodeParameter('codigo_sku', 0),
codigo_ean: this.getNodeParameter('codigo_ean', 0),
observacao: this.getNodeParameter('observacao', 0),
formato: this.getNodeParameter('formato', 0),
estoque: {
estoque_disponivel: this.getNodeParameter('estoque_disponivel', 0),
valor_venda: this.getNodeParameter('valor_venda', 0),
custo_medio: this.getNodeParameter('custo_medio', 0),
estoque_minimo: this.getNodeParameter('estoque_minimo', 0),
estoque_maximo: this.getNodeParameter('estoque_maximo', 0),
},
dimensao: {
altura: this.getNodeParameter('altura', 0),
largura: this.getNodeParameter('largura', 0),
profundidade: this.getNodeParameter('profundidade', 0),
},
};
const response = await this.helpers.requestOAuth2.call(this, 'contaAzulOAuth2Api', {
method: 'POST',
url: 'https://api-v2.contaazul.com/v1/produto',
body,
json: true,
});
return [{ json: response }];
}
//# sourceMappingURL=produtos.js.map