n8n-nodes-placid
Version:
n8n node to interact with Placid API for creative generation
52 lines • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = execute;
const n8n_workflow_1 = require("n8n-workflow");
const config_1 = require("../../utils/config");
async function execute(index) {
try {
const templateId = this.getNodeParameter('templateId', index);
const updateFields = this.getNodeParameter('updateFields', index, {});
if (!templateId) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Template ID is required', {
itemIndex: index,
});
}
const body = {};
if (updateFields.title) {
body.title = updateFields.title;
}
if (updateFields.tags) {
body.tags = updateFields.tags.split(',').map(tag => tag.trim());
}
if (updateFields.custom_data !== undefined) {
body.custom_data = updateFields.custom_data;
}
if (Object.keys(body).length === 0) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'At least one field must be provided for update', {
itemIndex: index,
});
}
const options = {
method: 'PATCH',
url: `${config_1.PlacidConfig.getRestUrl(config_1.PlacidConfig.ENDPOINTS.TEMPLATES)}/${templateId}`,
headers: {
'Accept': config_1.PlacidConfig.HTTP.HEADERS.ACCEPT,
'Content-Type': config_1.PlacidConfig.HTTP.HEADERS.CONTENT_TYPE,
'x-placid-integration': config_1.PlacidConfig.HTTP.HEADERS.PLACID_INTEGRATION,
},
body,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'placidApi', options);
return {
json: response,
pairedItem: { item: index },
};
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to update template: ${error.message}`, {
itemIndex: index,
});
}
}
//# sourceMappingURL=update.operation.js.map