UNPKG

@couleetech/n8n-nodes-enlightenedmsp

Version:

n8n node for EnlightenedMSP ticketing and workflow automation

138 lines (137 loc) 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeclockClockOut = 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 clockOut(id, message, ticketUpdateData, fields) { const query = ` mutation timeclockClockout($id: Float!, $message: String, $ticketUpdateData: JSON) { timeclockClockout(id: $id, message: $message, ticketUpdateData: $ticketUpdateData) { ${fields || DEFAULT_FIELDS} } } `; const variables = { id, message, ticketUpdateData, }; return this.executeGraphql(query, variables); } } class TimeclockClockOut { constructor() { this.description = { displayName: 'Timeclock Clock Out', name: 'timeclockClockOut', icon: 'file:enlightenedmsp.svg', group: ['transform'], version: 1, description: 'Clock out a user in the timeclock system', defaults: { name: 'Timeclock Clock Out', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'enlightenedMspGraphql', required: true, }, ], properties: [ { displayName: 'Timeclock ID', name: 'id', type: 'number', default: 0, required: true, description: 'The ID of the timeclock entry to clock out of', }, { displayName: 'Message', name: 'message', type: 'string', default: '', required: false, description: 'Optional message to include with the clock out', }, { displayName: 'Ticket Update Data', name: 'ticketUpdateData', type: 'json', default: '{}', required: false, description: 'Optional JSON data to update the ticket with', }, { 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 id = this.getNodeParameter('id', i); const message = this.getNodeParameter('message', i, undefined); const ticketUpdateData = this.getNodeParameter('ticketUpdateData', i, undefined); const dataSelection = this.getNodeParameter('dataSelection', i, undefined); const response = await api.clockOut(id, message, ticketUpdateData, dataSelection); returnData.push({ json: response.timeclockClockout, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } return [returnData]; } } exports.TimeclockClockOut = TimeclockClockOut;