@poli-digital/n8n-nodes-poli
Version:
Nó para interagir com a API da Poli
135 lines • 4.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateApp = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("./transport");
class CreateApp {
constructor() {
this.description = {
displayName: 'Create App',
name: 'createApp',
icon: 'file:poli.svg',
group: ['output'],
version: 1,
description: 'Create a new application',
defaults: {
name: 'Create App',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'poliApi',
required: true,
},
],
properties: [
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Visibility',
name: 'visibility',
type: 'options',
options: [
{ name: 'Public', value: 'public' },
{ name: 'Private', value: 'private' },
],
default: 'public',
required: true,
},
{
displayName: 'App Name',
name: 'appName',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Responsible',
name: 'responsible',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Phone',
name: 'phone',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Picture File ID',
name: 'pictureFileId',
type: 'string',
default: '',
required: false,
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const accountId = this.getNodeParameter('accountId', i);
const visibility = this.getNodeParameter('visibility', i);
const appName = this.getNodeParameter('appName', i);
const description = this.getNodeParameter('description', i);
const responsible = this.getNodeParameter('responsible', i);
const phone = this.getNodeParameter('phone', i);
const email = this.getNodeParameter('email', i);
const pictureFileId = this.getNodeParameter('pictureFileId', i, '');
const body = {
visibility: visibility.toUpperCase(),
attributes: {
name: appName,
description,
responsible,
phone,
email,
picture: pictureFileId ? { file_id: pictureFileId } : undefined,
},
attachments: [],
settings: [
{
type: 'link',
name: 'webhook',
placeholder: 'https://example.com/webhook',
},
],
resources: [],
};
const endpoint = `/accounts/${accountId}/applications?include=attributes`;
const responseData = await transport_1.apiRequest.call(this, 'POST', endpoint, body);
returnData.push({ json: responseData });
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
return [returnData];
}
}
exports.CreateApp = CreateApp;
//# sourceMappingURL=CreateApp.operation.js.map