UNPKG

@couleetech/n8n-nodes-enlightenedmsp

Version:

n8n node for EnlightenedMSP ticketing and workflow automation

118 lines (117 loc) 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeclockClockIn = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GraphqlBase_1 = require("./GraphqlBase"); const DEFAULT_FIELDS = `id start originalStart end originalEnd lastActive ticketId todoId coreUserId autotaskUserId isDispatchedTicket message ticketCompleted ticketUpdateData fromRole mergeFromTicketId isSynced`; class TimeclockApi extends GraphqlBase_1.GraphqlBase { async clockIn(ticketId, fields) { const query = ` mutation timeclockClockin($ticketId: Float!) { timeclockClockin(ticketId: $ticketId) { ${fields || DEFAULT_FIELDS} } } `; const variables = { ticketId, }; return this.executeGraphql(query, variables); } } class TimeclockClockIn { constructor() { this.description = { displayName: 'Timeclock Clock In', name: 'timeclockClockIn', icon: 'file:enlightenedmsp.svg', group: ['transform'], version: 1, description: 'Clock in a user in the timeclock system', defaults: { name: 'Timeclock Clock In', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'enlightenedMspGraphql', required: true, }, ], properties: [ { displayName: 'Ticket ID', name: 'ticketId', type: 'number', default: 0, required: true, description: 'The ID of the ticket to clock into', }, { displayName: 'Data Selection', name: 'dataSelection', type: 'string', typeOptions: { rows: 8, }, default: DEFAULT_FIELDS, required: false, noDataExpression: true, description: 'Fields to return in the response. Leave empty to use default fields.', placeholder: `Example fields: id start end ticketId message`, }, ], }; } async execute() { const credentials = await GraphqlBase_1.GraphqlBase.getCredentials(this); const api = new TimeclockApi(credentials.endpoint, credentials.apiKey, credentials.userId); const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const ticketId = this.getNodeParameter('ticketId', i); const dataSelection = this.getNodeParameter('dataSelection', i, undefined); const response = await api.clockIn(ticketId, dataSelection); returnData.push({ json: response.timeclockClockin, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } return [returnData]; } } exports.TimeclockClockIn = TimeclockClockIn;