UNPKG

n8n-nodes-smartsuite

Version:
49 lines 2.08 kB
"use strict"; // src/nodes/SmartSuite/actions/table/createTableField.operation.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const utils_1 = require("../../helpers/utils"); const smartSuiteApi_1 = require("../../transport/smartSuiteApi"); const validation_1 = require("../../helpers/validation"); async function execute() { (0, utils_1.debugLog)('[Table] createTableField.execute called', this.getNode().parameters, 2); const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const tableId = await validation_1.getTableId.call(this, i); const fieldName = this.getNodeParameter('fieldName', i); const fieldType = this.getNodeParameter('fieldType', i); const helpText = this.getNodeParameter('helpText', i); // Generate a valid slug from the field name const slug = fieldName .toLowerCase() .replace(/[^a-z0-9]+/g, '_') .replace(/^_+|_+$/g, ''); // Build params for text fields const params = fieldType === 'textfield' ? { max_length: 255, help_text: helpText, help_text_display_format: 'tooltip' } : {}; const body = { field: { name: fieldName, label: fieldName, field_type: fieldType, slug, params, }, field_position: { position: 1 }, auto_fill_structure_layout: true, }; (0, utils_1.debugLog)('[Table] createTableField.payload', body, 2); try { await smartSuiteApi_1.apiRequest.call(this, 'POST', `/applications/${tableId}/add_field/`, body); returnData.push({ json: { success: true } }); } catch (err) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), err.message, { itemIndex: i }); } } return returnData; } //# sourceMappingURL=createTableField.operation.js.map