UNPKG

@couleetech/n8n-nodes-enlightenedmsp

Version:

n8n node for EnlightenedMSP ticketing and workflow automation

130 lines (129 loc) 4.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateTodo = void 0; const CreateTodo_graphql_1 = require("./CreateTodo.graphql"); const GraphqlBase_1 = require("./GraphqlBase"); class CreateTodo { constructor() { this.description = { displayName: 'Create Todo', name: 'createTodo', icon: 'file:enlightenedmsp.svg', group: ['transform'], version: 1, description: 'Create a new todo in EnlightenedMSP', defaults: { name: 'Create Todo', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'enlightenedMspGraphql', required: true, }, ], properties: [ { displayName: 'Title', name: 'title', type: 'string', default: '', required: true, description: 'Title of the todo', }, { displayName: 'Description', name: 'description', type: 'string', typeOptions: { rows: 4, }, default: '', description: 'Description of the todo', }, { displayName: 'Due Date', name: 'dueDate', type: 'dateTime', default: '', description: 'Due date for the todo', }, { displayName: 'Ticket Blocking', name: 'ticketBlocking', type: 'boolean', default: false, description: 'Whether this todo blocks the ticket', }, { displayName: 'Autotask Ticket ID', name: 'autotaskTicketId', type: 'number', default: 0, description: 'ID of the associated Autotask ticket', }, { displayName: 'Is Onsite', name: 'isOnsite', type: 'boolean', default: false, description: 'Whether this todo requires onsite work', }, { displayName: 'Estimated Minutes', name: 'estimatedMinutes', type: 'number', default: 0, description: 'Estimated time to complete in minutes', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const length = items.length; const { endpoint, apiKey } = await GraphqlBase_1.GraphqlBase.getCredentials(this); const createTodoGraphql = new CreateTodo_graphql_1.CreateTodoGraphql(endpoint, apiKey); for (let i = 0; i < length; i++) { try { const title = this.getNodeParameter('title', i); const description = this.getNodeParameter('description', i); const dueDate = this.getNodeParameter('dueDate', i); const ticketBlocking = this.getNodeParameter('ticketBlocking', i); const autotaskTicketId = this.getNodeParameter('autotaskTicketId', i); const isOnsite = this.getNodeParameter('isOnsite', i); const estimatedMinutes = this.getNodeParameter('estimatedMinutes', i); const variables = { title, description, dueDate: dueDate ? new Date(dueDate) : undefined, ticketBlocking, autotaskTicketId: autotaskTicketId || undefined, isOnsite, estimatedMinutes: estimatedMinutes || undefined, createdByModuleName: 'N8N_WORKFLOW', createdByModuleId: `${this.getNode().id}`, }; const result = await createTodoGraphql.createTodo(variables); returnData.push({ json: result.createTodosTodo, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw error; } } return [returnData]; } } exports.CreateTodo = CreateTodo;