UNPKG

@traien/n8n-nodes-espocrm

Version:
103 lines 4.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CallHandler = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("../GenericFunctions"); const Utils_1 = require("./Utils"); class CallHandler { async create(index) { const entityData = {}; entityData.name = this.getNodeParameter('name', index); entityData.dateStart = this.getNodeParameter('dateStart', index); entityData.dateEnd = this.getNodeParameter('dateEnd', index); const additionalFields = this.getNodeParameter('additionalFields', index, {}); Object.assign(entityData, additionalFields); if (entityData.dateStart) { const ds = (0, Utils_1.toEspoDateTime)(entityData.dateStart); entityData.dateStart = ds; entityData.dateStartDate = (0, Utils_1.toEspoDate)(ds); } if (entityData.dateEnd) { const de = (0, Utils_1.toEspoDateTime)(entityData.dateEnd); entityData.dateEnd = de; entityData.dateEndDate = (0, Utils_1.toEspoDate)(de); } const endpoint = '/call'; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'POST', endpoint, entityData); return responseData; } async get(index) { const id = this.getNodeParameter('callId', index); const endpoint = `/call/${id}`; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'GET', endpoint); return responseData; } async update(index) { const id = this.getNodeParameter('callId', index); const updateFields = this.getNodeParameter('updateFields', index, {}); if (updateFields.dateStart) { const ds = (0, Utils_1.toEspoDateTime)(updateFields.dateStart); updateFields.dateStart = ds; updateFields.dateStartDate = (0, Utils_1.toEspoDate)(ds); } if (updateFields.dateEnd) { const de = (0, Utils_1.toEspoDateTime)(updateFields.dateEnd); updateFields.dateEnd = de; updateFields.dateEndDate = (0, Utils_1.toEspoDate)(de); } const endpoint = `/call/${id}`; const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'PATCH', endpoint, updateFields); return responseData; } async delete(index) { const id = this.getNodeParameter('callId', index); const endpoint = `/call/${id}`; await GenericFunctions_1.espoApiRequest.call(this, 'DELETE', endpoint); return { success: true, entityType: 'call', id, message: 'Call deleted successfully' }; } async getAll(index) { const returnAll = this.getNodeParameter('returnAll', index); const endpoint = '/call'; 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.CallHandler = CallHandler; //# sourceMappingURL=CallHandler.js.map