UNPKG

n8n-nodes-cigotracker

Version:

n8n node for CigoTracker API integration - manage deliveries, routes, and field service operations

120 lines (119 loc) 4.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CigoTracker = void 0; const CigoTracker_helpers_1 = require("./CigoTracker.helpers"); class CigoTracker { constructor() { this.description = { displayName: 'CigoTracker', name: 'cigoTracker', icon: 'file:Cigo-Logo.png', group: ['transform'], version: 1, subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}', description: 'Interact with CigoTracker API', defaults: { name: 'CigoTracker', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'cigoTrackerApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Job', value: 'job', description: 'Create, read, update, and delete jobs', }, ], default: 'job', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['job'], }, }, options: [ { name: 'Ping', value: 'ping', description: 'Test API connection', action: 'Test connection', }, { name: 'Get All Jobs', value: 'getAll', description: 'Get all jobs', action: 'Get all jobs', }, ], default: 'ping', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const length = items.length > 0 ? items.length : 1; const resource = this.getNodeParameter('resource', 0); for (let i = 0; i < length; i++) { try { const operation = this.getNodeParameter('operation', 0); let responseData; if (resource === 'job') { if (operation === 'ping') { responseData = await CigoTracker_helpers_1.cigoTrackerApiRequest.call(this, 'GET', '/ping'); } else if (operation === 'getAll') { responseData = await CigoTracker_helpers_1.cigoTrackerApiRequest.call(this, 'GET', '/jobs'); } } if (Array.isArray(responseData)) { for (const item of responseData) { returnData.push({ json: item, pairedItem: i, }); } } else if (responseData) { returnData.push({ json: responseData, pairedItem: i, }); } } catch (error) { if (this.continueOnFail()) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; returnData.push({ json: { error: errorMessage, }, pairedItem: i, }); continue; } throw error; } } return [returnData]; } } exports.CigoTracker = CigoTracker;