UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

139 lines 4.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = exports.properties = void 0; exports.execute = execute; const utilities_1 = require("../../../../../../utils/utilities"); const descriptions_1 = require("../../descriptions"); const utils_1 = require("../../helpers/utils"); const transport_1 = require("../../transport"); exports.properties = [ { displayName: 'From All Calendars', name: 'fromAllCalendars', type: 'boolean', default: true, }, { ...descriptions_1.calendarRLC, displayOptions: { show: { fromAllCalendars: [false], }, }, }, ...descriptions_1.returnAllOrLimit, { displayName: 'Output', name: 'output', type: 'options', default: 'simple', options: [ { name: 'Simplified', value: 'simple', }, { name: 'Raw', value: 'raw', }, { name: 'Select Included Fields', value: 'fields', }, ], }, { displayName: 'Fields', name: 'fields', type: 'multiOptions', description: 'The fields to add to the output', displayOptions: { show: { output: ['fields'], }, }, options: utils_1.eventfields, default: [], }, { displayName: 'Filters', name: 'filters', type: 'collection', placeholder: 'Add Filter', default: {}, options: [ { displayName: 'Filter Query', name: 'custom', type: 'string', default: '', placeholder: "e.g. contains(subject,'Hello')", hint: 'Search query to filter events. <a href="https://learn.microsoft.com/en-us/graph/filter-query-parameter">More info</a>.', }, ], }, ]; const displayOptions = { show: { resource: ['event'], operation: ['getAll'], }, }; exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, exports.properties); async function execute(index) { const responseData = []; const qs = {}; const returnAll = this.getNodeParameter('returnAll', index); const filters = this.getNodeParameter('filters', index, {}); const output = this.getNodeParameter('output', index); if (output === 'fields') { const fields = this.getNodeParameter('fields', index); qs.$select = fields.join(','); } if (output === 'simple') { qs.$select = 'id,subject,bodyPreview,start,end,organizer,attendees,webLink'; } if (Object.keys(filters).length) { const filterString = []; if (filters.custom) { filterString.push(filters.custom); } if (filterString.length) { qs.$filter = filterString.join(' and '); } } const calendars = []; const fromAllCalendars = this.getNodeParameter('fromAllCalendars', index); if (fromAllCalendars) { const response = await transport_1.microsoftApiRequest.call(this, 'GET', '/calendars', undefined, { $select: 'id', }); for (const calendar of response.value) { calendars.push(calendar.id); } } else { const calendarId = this.getNodeParameter('calendarId', index, undefined, { extractValue: true, }); calendars.push(calendarId); } const limit = this.getNodeParameter('limit', index, 0); for (const calendarId of calendars) { const endpoint = `/calendars/${calendarId}/events`; if (returnAll) { const response = await transport_1.microsoftApiRequestAllItems.call(this, 'value', 'GET', endpoint, undefined, qs); responseData.push(...response); } else { qs.$top = limit - responseData.length; if (qs.$top <= 0) break; const response = await transport_1.microsoftApiRequest.call(this, 'GET', endpoint, undefined, qs); responseData.push(...response.value); } } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: index } }); return executionData; } //# sourceMappingURL=getAll.operation.js.map