n8n-nodes-everest-tms
Version:
Everest TMS n8n integration
43 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeAlertOperations = executeAlertOperations;
const GenericFunctions_1 = require("../GenericFunctions");
async function executeAlertOperations(itemIndex) {
const operation = this.getNodeParameter('operation', itemIndex);
if (operation === 'getMany') {
const options = this.getNodeParameter('options', itemIndex, {});
const body = (0, GenericFunctions_1.cleanObject)(options);
// Handle pagination
if (body.limit && body.limit > 0) {
// Use custom limit_start if provided, otherwise default to 0
const limitStart = body.limit_start || 0;
body.limit_start = limitStart;
body.limit_end = limitStart + body.limit;
delete body.limit;
const response = await GenericFunctions_1.everestApiRequest.call(this, 'POST', '/alerts', body);
return response.alerts || [];
}
else {
return await GenericFunctions_1.everestApiRequestAllItems.call(this, 'alerts', 'POST', '/alerts', body);
}
}
if (operation === 'create') {
const icon = this.getNodeParameter('icon', itemIndex);
const category = this.getNodeParameter('category', itemIndex);
const text = this.getNodeParameter('text', itemIndex);
const createdFor = this.getNodeParameter('created_for', itemIndex);
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {});
(0, GenericFunctions_1.validateRequiredFields)({ icon, category, text, created_for: createdFor }, ['icon', 'category', 'text', 'created_for']);
const body = {
icon,
category,
text,
created_for: createdFor,
...(0, GenericFunctions_1.cleanObject)(additionalFields),
};
const response = await GenericFunctions_1.everestApiRequest.call(this, 'POST', '/alerts/create', body);
return response.alert || response;
}
throw new Error(`The operation "${operation}" is not known!`);
}
//# sourceMappingURL=AlertOperations.js.map