UNPKG

@couleetech/n8n-nodes-enlightenedmsp

Version:

n8n node for EnlightenedMSP ticketing and workflow automation

244 lines (243 loc) 9.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateTicket = void 0; const GraphqlBase_1 = require("./GraphqlBase"); const DEFAULT_FIELDS = `id title status ticketNumber description priority dueDateTime createDate completedDate assignedResourceID queueID resolution coreCompanyId archived`; class UpdateTicketGraphql extends GraphqlBase_1.GraphqlBase { async updateTicket(variables) { const query = ` mutation UpdateAutotaskTickets( $id: Int! $parentTicketId: Int $title: String $status: Int $priority: Int $queueID: Int $assignedResourceID: Int $dueDateTime: Date $resolution: String $completedDate: Date $coreCompanyId: Int $archived: Boolean $nextActionNote: String ) { updateAutotaskTickets( id: $id parentTicketId: $parentTicketId title: $title status: $status priority: $priority queueID: $queueID assignedResourceID: $assignedResourceID dueDateTime: $dueDateTime resolution: $resolution completedDate: $completedDate coreCompanyId: $coreCompanyId archived: $archived nextActionNote: $nextActionNote ) { ${variables.fields || DEFAULT_FIELDS} } } `; return this.executeGraphql(query, variables); } } class UpdateTicket { constructor() { this.description = { displayName: 'Update Ticket', name: 'updateTicket', icon: 'file:enlightenedmsp.svg', group: ['transform'], version: 1, description: 'Updates a ticket in EnlightenedMSP', defaults: { name: 'Update Ticket', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'enlightenedMspGraphql', required: true, }, ], properties: [ { displayName: 'Ticket ID', name: 'id', type: 'number', default: 0, required: true, description: 'The ID of the ticket to update', }, { displayName: 'Update Fields', name: 'updateFields', type: 'collection', placeholder: 'Add Field', default: {}, options: [ { displayName: 'Parent Ticket ID', name: 'parentTicketId', type: 'number', default: 0, description: 'The ID of the parent ticket', }, { displayName: 'Title', name: 'title', type: 'string', default: '', description: 'The title of the ticket', }, { displayName: 'Status', name: 'status', type: 'number', default: 0, description: 'The status of the ticket', }, { displayName: 'Priority', name: 'priority', type: 'number', default: 0, description: 'The priority of the ticket', }, { displayName: 'Queue ID', name: 'queueID', type: 'number', default: 0, description: 'The queue ID of the ticket', }, { displayName: 'Core Company ID', name: 'coreCompanyId', type: 'number', default: 0, description: 'The core company ID associated with the ticket', }, { displayName: 'Archived', name: 'archived', type: 'boolean', default: false, description: 'Whether the ticket is archived', }, { displayName: 'Assigned Resource ID', name: 'assignedResourceID', type: 'number', default: 0, description: 'The ID of the assigned resource', }, { displayName: 'Due Date Time', name: 'dueDateTime', type: 'dateTime', default: '', description: 'The due date and time of the ticket', }, { displayName: 'Resolution', name: 'resolution', type: 'string', default: '', description: 'The resolution of the ticket', }, { displayName: 'Completed Date', name: 'completedDate', type: 'dateTime', default: '', description: 'The completion date of the ticket', }, { displayName: 'Next Action Note', name: 'nextActionNote', type: 'string', default: '', description: 'The next action note for the ticket', }, ], }, { 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 title status ticketNumber description`, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const { endpoint, apiKey } = await UpdateTicketGraphql.getCredentials(this); const graphqlClient = new UpdateTicketGraphql(endpoint, apiKey); for (let i = 0; i < items.length; i++) { try { const id = this.getNodeParameter('id', i); const updateFields = this.getNodeParameter('updateFields', i); const dataSelection = this.getNodeParameter('dataSelection', i, undefined); const variables = { id, ...updateFields, fields: dataSelection, }; if (updateFields.dueDateTime) { variables.dueDateTime = new Date(updateFields.dueDateTime); } if (updateFields.completedDate) { variables.completedDate = new Date(updateFields.completedDate); } const result = await graphqlClient.updateTicket(variables); returnData.push({ json: result.updateAutotaskTickets, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw error; } } return [returnData]; } } exports.UpdateTicket = UpdateTicket;