n8n-nodes-gohighlevel
Version:
n8n node for GoHighLevel API v2
50 lines • 2.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleCustomFieldOperations = void 0;
const gohighlevel_1 = require("../../utils/gohighlevel");
async function handleCustomFieldOperations(operation, i) {
const GHLEngine = await gohighlevel_1.GoHighLevelManager.getInstance(this);
if (operation === 'create') {
const model = this.getNodeParameter('model', i);
const data = {
name: this.getNodeParameter('name', i),
dataType: this.getNodeParameter('dataType', i),
model,
...this.getNodeParameter('additionalFields', i, {}),
};
if (data.dataType === 'SELECT') {
const options = this.getNodeParameter('options', i).split(',').map(opt => opt.trim());
data.options = options;
}
const defaultValue = this.getNodeParameter('defaultValue', i);
if (defaultValue) {
data.defaultValue = defaultValue;
}
return GHLEngine.createCustomField(model, data);
}
if (operation === 'update') {
const customFieldId = this.getNodeParameter('customFieldId', i);
const data = {
...this.getNodeParameter('additionalFields', i, {}),
};
if (data.type === 'select') {
const options = this.getNodeParameter('options', i).split(',').map(opt => opt.trim());
data.options = options;
}
return GHLEngine.updateCustomField(customFieldId, data);
}
if (operation === 'get') {
const customFieldId = this.getNodeParameter('customFieldId', i);
return GHLEngine.getCustomField(customFieldId);
}
if (operation === 'getAll') {
return GHLEngine.getCustomFields();
}
if (operation === 'delete') {
const customFieldId = this.getNodeParameter('customFieldId', i);
return GHLEngine.deleteCustomField(customFieldId);
}
throw new Error(`Unknown operation: ${operation}`);
}
exports.handleCustomFieldOperations = handleCustomFieldOperations;
//# sourceMappingURL=customField.handler.js.map