@traien/n8n-nodes-espocrm
Version:
n8n integration with EspoCRM
80 lines • 3.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CaseHandler = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const GenericFunctions_1 = require("../GenericFunctions");
class CaseHandler {
async create(index) {
const entityData = {};
entityData.name = this.getNodeParameter('name', index);
const additionalFields = this.getNodeParameter('additionalFields', index, {});
Object.assign(entityData, additionalFields);
const endpoint = '/case';
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'POST', endpoint, entityData);
return responseData;
}
async get(index) {
const id = this.getNodeParameter('caseId', index);
const endpoint = `/case/${id}`;
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'GET', endpoint);
return responseData;
}
async update(index) {
const id = this.getNodeParameter('caseId', index);
const updateFields = this.getNodeParameter('updateFields', index, {});
const endpoint = `/case/${id}`;
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'PATCH', endpoint, updateFields);
return responseData;
}
async delete(index) {
const id = this.getNodeParameter('caseId', index);
const endpoint = `/case/${id}`;
await GenericFunctions_1.espoApiRequest.call(this, 'DELETE', endpoint);
return { success: true, entityType: 'case', id, message: 'Case deleted successfully' };
}
async getAll(index) {
const returnAll = this.getNodeParameter('returnAll', index);
const endpoint = '/case';
const qs = {};
const filterOptions = this.getNodeParameter('filterOptions', index, {});
if (filterOptions.where) {
if (typeof filterOptions.where === 'string') {
try {
qs.where = JSON.parse(filterOptions.where);
}
catch (e) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in 'where' parameter: ${e.message}`);
}
}
else {
qs.where = filterOptions.where;
}
}
if (filterOptions.orderBy)
qs.orderBy = filterOptions.orderBy;
if (filterOptions.order)
qs.order = filterOptions.order;
if (filterOptions.select)
qs.select = filterOptions.select;
if (filterOptions.offset)
qs.offset = filterOptions.offset;
if (filterOptions.boolFilterList)
qs.boolFilterList = filterOptions.boolFilterList;
if (filterOptions.primaryFilter)
qs.primaryFilter = filterOptions.primaryFilter;
const headers = {};
if (filterOptions.skipTotalCount === true)
headers['X-No-Total'] = 'true';
if (returnAll === true) {
return await GenericFunctions_1.espoApiRequestAllItems.call(this, 'GET', endpoint, {}, qs);
}
else {
const limit = this.getNodeParameter('limit', index);
qs.maxSize = limit;
const response = await GenericFunctions_1.espoApiRequest.call(this, 'GET', endpoint, {}, qs, undefined, headers);
return response.list;
}
}
}
exports.CaseHandler = CaseHandler;
//# sourceMappingURL=CaseHandler.js.map