n8n-nodes-gohighlevel
Version:
n8n node for GoHighLevel API v2
60 lines • 2.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleCompanyOperations = void 0;
const gohighlevel_1 = require("../../utils/gohighlevel");
async function handleCompanyOperations(operation, i) {
const GHLEngine = await gohighlevel_1.GoHighLevelManager.getInstance(this);
if (operation === 'create') {
const data = {
name: this.getNodeParameter('name', i),
website: this.getNodeParameter('website', i),
industry: this.getNodeParameter('industry', i),
description: this.getNodeParameter('description', i),
...this.getNodeParameter('additionalFields', i, {}),
};
return GHLEngine.createCompany(data);
}
if (operation === 'update') {
const companyId = this.getNodeParameter('companyId', i);
const data = {
name: this.getNodeParameter('name', i),
website: this.getNodeParameter('website', i),
industry: this.getNodeParameter('industry', i),
description: this.getNodeParameter('description', i),
...this.getNodeParameter('additionalFields', i, {}),
};
return GHLEngine.updateCompany(companyId, data);
}
if (operation === 'get') {
const companyId = this.getNodeParameter('companyId', i);
return GHLEngine.getCompany(companyId);
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i);
if (returnAll) {
return GHLEngine.getCompanies({ params: filters });
}
else {
const limit = this.getNodeParameter('limit', i);
return GHLEngine.getCompanies({ params: { ...filters, limit } });
}
}
if (operation === 'delete') {
const companyId = this.getNodeParameter('companyId', i);
return GHLEngine.deleteCompany(companyId);
}
if (operation === 'addTag') {
const companyId = this.getNodeParameter('companyId', i);
const tags = this.getNodeParameter('tags', i).split(',').map(tag => tag.trim());
return GHLEngine.addTagsToCompany(companyId, tags);
}
if (operation === 'removeTag') {
const companyId = this.getNodeParameter('companyId', i);
const tags = this.getNodeParameter('tags', i).split(',').map(tag => tag.trim());
return GHLEngine.removeTagsFromCompany(companyId, tags);
}
throw new Error(`Unknown operation: ${operation}`);
}
exports.handleCompanyOperations = handleCompanyOperations;
//# sourceMappingURL=company.handler.js.map