@traien/n8n-nodes-espocrm
Version:
n8n integration with EspoCRM
101 lines • 4.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskHandler = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const GenericFunctions_1 = require("../GenericFunctions");
const Utils_1 = require("./Utils");
class TaskHandler {
async create(index) {
const entityData = {};
entityData.name = this.getNodeParameter('name', 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 = '/task';
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'POST', endpoint, entityData);
return responseData;
}
async get(index) {
const id = this.getNodeParameter('taskId', index);
const endpoint = `/task/${id}`;
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'GET', endpoint);
return responseData;
}
async update(index) {
const id = this.getNodeParameter('taskId', 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 = `/task/${id}`;
const responseData = await GenericFunctions_1.espoApiRequest.call(this, 'PATCH', endpoint, updateFields);
return responseData;
}
async delete(index) {
const id = this.getNodeParameter('taskId', index);
const endpoint = `/task/${id}`;
await GenericFunctions_1.espoApiRequest.call(this, 'DELETE', endpoint);
return { success: true, entityType: 'task', id, message: 'Task deleted successfully' };
}
async getAll(index) {
const returnAll = this.getNodeParameter('returnAll', index);
const endpoint = '/task';
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.TaskHandler = TaskHandler;
//# sourceMappingURL=TaskHandler.js.map