n8n-nodes-v4-companynodes
Version:
145 lines • 5.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetContentFields = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class GetContentFields {
constructor() {
this.description = {
displayName: 'FWO Get Content Fields',
name: 'getContentFields',
icon: 'file:icon.svg',
group: ['input'],
version: 1,
description: 'Consume FWO API to fetch content fields using multiple Field IDs and optional Card ID',
defaults: {
name: 'FWO Get Content Fields',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'fwoCredentialsApi',
required: true,
},
],
properties: [
{
displayName: 'Field IDs',
name: 'fieldIds',
type: 'fixedCollection',
placeholder: 'Add Field ID',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'ids',
displayName: 'IDs',
values: [
{
displayName: 'Field ID',
name: 'id',
type: 'string',
default: '',
placeholder: 'Id do campo',
description: 'pega o id do campo sendo o usuário root',
required: true,
},
],
},
],
},
{
displayName: 'Card ID (Optional)',
name: 'cardId',
type: 'string',
default: '',
placeholder: 'Enter a Card ID',
description: 'The optional Card ID to refine the data',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const credentials = await this.getCredentials('fwoCredentialsApi');
if (!credentials) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials returned!' + credentials);
}
for (let i = 0; i < items.length; i++) {
try {
const fieldIds = this.getNodeParameter('fieldIds.ids', i, []);
const cardId = this.getNodeParameter('cardId', i, '');
for (const { id: fieldId } of fieldIds) {
const query = `
query FieldsValues($where: FieldsValueWhereInput, $orderBy: [FieldsValueOrderByWithRelationInput!], $take: Int) {
fieldsValues(where: $where, orderBy: $orderBy, take: $take) {
id
card {
name
id
}
field {
id
name
}
content
}
}
`;
const variables = {
where: {
AND: [
{
fieldId: {
equals: parseInt(fieldId, 10),
},
},
],
},
orderBy: {
createdAt: 'desc',
},
take: 1,
};
if (cardId) {
variables.where.AND.push({
cardId: {
equals: cardId,
},
});
}
const response = await this.helpers.request({
method: 'POST',
url: credentials.url,
headers: credentials.headers,
body: JSON.stringify({
query,
variables,
}),
json: true,
});
returnData.push({
json: {
fieldId,
cardId: cardId || null,
response: response.data,
},
});
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } });
continue;
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
return [returnData];
}
}
exports.GetContentFields = GetContentFields;
//# sourceMappingURL=GetContentFields.node.js.map