UNPKG

@traien/n8n-nodes-espocrm

Version:
94 lines 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomEntityHandler = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("../GenericFunctions"); class CustomEntityHandler { async create(index) { const entityType = this.getNodeParameter('entityType', index); const entityData = JSON.parse(this.getNodeParameter('data', index)); const endpoint = `/${entityType}`; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'POST', endpoint, entityData); return responseData; } async get(index) { const entityType = this.getNodeParameter('entityType', index); const recordId = this.getNodeParameter('id', index); const endpoint = `/${entityType}/${recordId}`; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'GET', endpoint); return responseData; } async update(index) { const entityType = this.getNodeParameter('entityType', index); const recordId = this.getNodeParameter('id', index); const entityData = JSON.parse(this.getNodeParameter('data', index)); const endpoint = `/${entityType}/${recordId}`; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'PATCH', endpoint, entityData); return responseData; } async delete(index) { const entityType = this.getNodeParameter('entityType', index); const recordId = this.getNodeParameter('id', index); const endpoint = `/${entityType}/${recordId}`; await GenericFunctions_1.espoApiRequest.call(this, 'DELETE', endpoint); return { success: true, entityType, id: recordId, message: `${entityType} deleted successfully` }; } async getAll(index) { const entityType = this.getNodeParameter('entityType', index); const returnAll = this.getNodeParameter('returnAll', index); const endpoint = `/${entityType}`; 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.CustomEntityHandler = CustomEntityHandler; //# sourceMappingURL=CustomEntityHandler.js.map