feat(Microsoft Outlook Node): Node overhaul (#4449)
[N8N-4995](https://linear.app/n8n/issue/N8N-4995) --------- Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import { calendarRLC } from '../../descriptions';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
calendarRLC,
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'subject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Start',
|
||||
name: 'startDateTime',
|
||||
type: 'dateTime',
|
||||
default: DateTime.now().toISO(),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'End',
|
||||
name: 'endDateTime',
|
||||
type: 'dateTime',
|
||||
required: true,
|
||||
default: DateTime.now().plus({ minutes: 30 }).toISO(),
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options
|
||||
displayName: 'Categories',
|
||||
name: 'categories',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCategoriesNames',
|
||||
},
|
||||
default: [],
|
||||
},
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'body',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Description Preview',
|
||||
name: 'bodyPreview',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Hide Attendees',
|
||||
name: 'hideAttendees',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to allow each attendee to only see themselves in the meeting request and meeting tracking list',
|
||||
},
|
||||
{
|
||||
displayName: 'Importance',
|
||||
name: 'importance',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 'low',
|
||||
},
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 'high',
|
||||
},
|
||||
],
|
||||
default: 'normal',
|
||||
},
|
||||
{
|
||||
displayName: 'Is All Day',
|
||||
name: 'isAllDay',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Cancelled',
|
||||
name: 'isCancelled',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Draft',
|
||||
name: 'isDraft',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Online Meeting',
|
||||
name: 'isOnlineMeeting',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Sensitivity',
|
||||
name: 'sensitivity',
|
||||
type: 'options',
|
||||
default: 'normal',
|
||||
options: [
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
value: 'personal',
|
||||
},
|
||||
{
|
||||
name: 'Private',
|
||||
value: 'private',
|
||||
},
|
||||
{
|
||||
name: 'Confidential',
|
||||
value: 'confidential',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Show As',
|
||||
name: 'showAs',
|
||||
type: 'options',
|
||||
default: 'free',
|
||||
options: [
|
||||
{
|
||||
name: 'Busy',
|
||||
value: 'busy',
|
||||
},
|
||||
{
|
||||
name: 'Free',
|
||||
value: 'free',
|
||||
},
|
||||
{
|
||||
name: 'Oof',
|
||||
value: 'oof',
|
||||
},
|
||||
{
|
||||
name: 'Tentative',
|
||||
value: 'tentative',
|
||||
},
|
||||
{
|
||||
name: 'Working Elsewhere',
|
||||
value: 'workingElsewhere',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Timezone',
|
||||
name: 'timeZone',
|
||||
type: 'options',
|
||||
default: 'UTC',
|
||||
options: moment.tz.names().map((name) => ({
|
||||
name,
|
||||
value: name,
|
||||
})),
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
default: 'singleInstance',
|
||||
options: [
|
||||
{
|
||||
name: 'Single Instance',
|
||||
value: 'singleInstance',
|
||||
},
|
||||
{
|
||||
name: 'Occurrence',
|
||||
value: 'occurrence',
|
||||
},
|
||||
{
|
||||
name: 'Exception',
|
||||
value: 'exception',
|
||||
},
|
||||
{
|
||||
name: 'Series Master',
|
||||
value: 'seriesMaster',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
let additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
|
||||
additionalFields = Object.keys(additionalFields).reduce((acc: IDataObject, key: string) => {
|
||||
if (additionalFields[key] !== '' || additionalFields[key] !== undefined) {
|
||||
acc[key] = additionalFields[key];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const calendarId = this.getNodeParameter('calendarId', index, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
if (calendarId === '') {
|
||||
throw new NodeOperationError(this.getNode(), 'Calendar ID is required');
|
||||
}
|
||||
const subject = this.getNodeParameter('subject', index) as string;
|
||||
|
||||
const endpoint = `/calendars/${calendarId}/events`;
|
||||
|
||||
let timeZone = 'UTC';
|
||||
|
||||
if (additionalFields.timeZone) {
|
||||
timeZone = additionalFields.timeZone as string;
|
||||
delete additionalFields.timeZone;
|
||||
}
|
||||
|
||||
if (additionalFields.body) {
|
||||
additionalFields.body = {
|
||||
content: additionalFields.body,
|
||||
contentType: 'html',
|
||||
};
|
||||
}
|
||||
|
||||
let startDateTime = this.getNodeParameter('startDateTime', index) as string;
|
||||
let endDateTime = this.getNodeParameter('endDateTime', index) as string;
|
||||
|
||||
if (additionalFields.isAllDay) {
|
||||
startDateTime = DateTime.fromISO(startDateTime, { zone: timeZone }).toFormat('yyyy-MM-dd');
|
||||
endDateTime = DateTime.fromISO(endDateTime, { zone: timeZone }).toFormat('yyyy-MM-dd');
|
||||
|
||||
const minimalWholeDayDuration = 24;
|
||||
const duration = DateTime.fromISO(startDateTime, { zone: timeZone }).diff(
|
||||
DateTime.fromISO(endDateTime, { zone: timeZone }),
|
||||
).hours;
|
||||
|
||||
if (duration < minimalWholeDayDuration) {
|
||||
endDateTime = DateTime.fromISO(startDateTime, { zone: timeZone }).plus({ hours: 24 }).toISO();
|
||||
}
|
||||
}
|
||||
|
||||
const body: IDataObject = {
|
||||
subject,
|
||||
start: {
|
||||
dateTime: startDateTime,
|
||||
timeZone,
|
||||
},
|
||||
end: {
|
||||
dateTime: endDateTime,
|
||||
timeZone,
|
||||
},
|
||||
...additionalFields,
|
||||
};
|
||||
|
||||
const responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { calendarRLC, eventRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [calendarRLC, eventRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const eventId = decodeOutlookId(
|
||||
this.getNodeParameter('eventId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
await microsoftApiRequest.call(this, 'DELETE', `/calendar/events/${eventId}`);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { decodeOutlookId, eventfields } from '../../helpers/utils';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { calendarRLC, eventRLC } from '../../descriptions';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
calendarRLC,
|
||||
eventRLC,
|
||||
{
|
||||
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: eventfields,
|
||||
default: [],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const qs = {} as IDataObject;
|
||||
|
||||
const eventId = decodeOutlookId(
|
||||
this.getNodeParameter('eventId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const output = this.getNodeParameter('output', index) as string;
|
||||
|
||||
if (output === 'fields') {
|
||||
const fields = this.getNodeParameter('fields', index) as string[];
|
||||
qs.$select = fields.join(',');
|
||||
}
|
||||
|
||||
if (output === 'simple') {
|
||||
qs.$select = 'id,subject,bodyPreview,start,end,organizer,attendees,webLink';
|
||||
}
|
||||
|
||||
const endpoint = `/calendar/events/${eventId}`;
|
||||
|
||||
const responseData = await microsoftApiRequest.call(this, 'GET', endpoint, undefined, qs);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { eventfields } from '../../helpers/utils';
|
||||
import { microsoftApiRequest, microsoftApiRequestAllItems } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { calendarRLC, returnAllOrLimit } from '../../descriptions';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'From All Calendars',
|
||||
name: 'fromAllCalendars',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
...calendarRLC,
|
||||
displayOptions: {
|
||||
show: {
|
||||
fromAllCalendars: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
...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: 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'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const responseData: IDataObject[] = [];
|
||||
const qs = {} as IDataObject;
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', index);
|
||||
const filters = this.getNodeParameter('filters', index, {});
|
||||
const output = this.getNodeParameter('output', index) as string;
|
||||
|
||||
if (output === 'fields') {
|
||||
const fields = this.getNodeParameter('fields', index) as string[];
|
||||
qs.$select = fields.join(',');
|
||||
}
|
||||
|
||||
if (output === 'simple') {
|
||||
qs.$select = 'id,subject,bodyPreview,start,end,organizer,attendees,webLink';
|
||||
}
|
||||
|
||||
if (Object.keys(filters).length) {
|
||||
const filterString: string[] = [];
|
||||
|
||||
if (filters.custom) {
|
||||
filterString.push(filters.custom as string);
|
||||
}
|
||||
|
||||
if (filterString.length) {
|
||||
qs.$filter = filterString.join(' and ');
|
||||
}
|
||||
}
|
||||
|
||||
const calendars: string[] = [];
|
||||
|
||||
const fromAllCalendars = this.getNodeParameter('fromAllCalendars', index) as boolean;
|
||||
|
||||
if (fromAllCalendars) {
|
||||
const response = await microsoftApiRequest.call(this, 'GET', '/calendars', undefined, {
|
||||
$select: 'id',
|
||||
});
|
||||
for (const calendar of response.value) {
|
||||
calendars.push(calendar.id as string);
|
||||
}
|
||||
} else {
|
||||
const calendarId = this.getNodeParameter('calendarId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
import * as create from './create.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as del from './delete.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, del as delete, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a new event',
|
||||
action: 'Create an event',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete an event',
|
||||
action: 'Delete an event',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Retrieve an event',
|
||||
action: 'Get an event',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'List and search events',
|
||||
action: 'Get many events',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update an event',
|
||||
action: 'Update an event',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...del.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,283 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import { calendarRLC, eventRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
calendarRLC,
|
||||
eventRLC,
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options
|
||||
displayName: 'Categories',
|
||||
name: 'categories',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCategoriesNames',
|
||||
},
|
||||
default: [],
|
||||
},
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'body',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Description Preview',
|
||||
name: 'bodyPreview',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'End',
|
||||
name: 'end',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Hide Attendees',
|
||||
name: 'hideAttendees',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to allow each attendee to only see themselves in the meeting request and meeting tracking list',
|
||||
},
|
||||
{
|
||||
displayName: 'Importance',
|
||||
name: 'importance',
|
||||
type: 'options',
|
||||
default: 'low',
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 'low',
|
||||
},
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 'high',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Is All Day',
|
||||
name: 'isAllDay',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Cancelled',
|
||||
name: 'isCancelled',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Draft',
|
||||
name: 'isDraft',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Is Online Meeting',
|
||||
name: 'isOnlineMeeting',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Sensitivity',
|
||||
name: 'sensitivity',
|
||||
type: 'options',
|
||||
default: 'normal',
|
||||
options: [
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
value: 'personal',
|
||||
},
|
||||
{
|
||||
name: 'Private',
|
||||
value: 'private',
|
||||
},
|
||||
{
|
||||
name: 'Confidential',
|
||||
value: 'confidential',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Show As',
|
||||
name: 'showAs',
|
||||
type: 'options',
|
||||
default: 'free',
|
||||
options: [
|
||||
{
|
||||
name: 'Busy',
|
||||
value: 'busy',
|
||||
},
|
||||
{
|
||||
name: 'Free',
|
||||
value: 'free',
|
||||
},
|
||||
{
|
||||
name: 'Oof',
|
||||
value: 'oof',
|
||||
},
|
||||
{
|
||||
name: 'Tentative',
|
||||
value: 'tentative',
|
||||
},
|
||||
{
|
||||
name: 'Working Elsewhere',
|
||||
value: 'workingElsewhere',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Start',
|
||||
name: 'start',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Timezone',
|
||||
name: 'timeZone',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'subject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
default: 'singleInstance',
|
||||
options: [
|
||||
{
|
||||
name: 'Single Instance',
|
||||
value: 'singleInstance',
|
||||
},
|
||||
{
|
||||
name: 'Occurrence',
|
||||
value: 'occurrence',
|
||||
},
|
||||
{
|
||||
name: 'Exception',
|
||||
value: 'exception',
|
||||
},
|
||||
{
|
||||
name: 'Series Master',
|
||||
value: 'seriesMaster',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['update'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
|
||||
const eventId = decodeOutlookId(
|
||||
this.getNodeParameter('eventId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
let timeZone = 'UTC';
|
||||
|
||||
if (additionalFields.timeZone) {
|
||||
timeZone = additionalFields.timeZone as string;
|
||||
delete additionalFields.timeZone;
|
||||
}
|
||||
|
||||
if (additionalFields.body) {
|
||||
additionalFields.body = {
|
||||
content: additionalFields.body,
|
||||
contentType: 'html',
|
||||
};
|
||||
}
|
||||
|
||||
let startDateTime = additionalFields.start as string;
|
||||
let endDateTime = additionalFields.end as string;
|
||||
|
||||
if (additionalFields.isAllDay) {
|
||||
startDateTime =
|
||||
DateTime.fromISO(startDateTime, { zone: timeZone }).toFormat('yyyy-MM-dd') ||
|
||||
DateTime.utc().toFormat('yyyy-MM-dd');
|
||||
endDateTime =
|
||||
DateTime.fromISO(endDateTime, { zone: timeZone }).toFormat('yyyy-MM-dd') ||
|
||||
DateTime.utc().toFormat('yyyy-MM-dd');
|
||||
|
||||
const minimalWholeDayDuration = 24;
|
||||
const duration = DateTime.fromISO(startDateTime, { zone: timeZone }).diff(
|
||||
DateTime.fromISO(endDateTime, { zone: timeZone }),
|
||||
).hours;
|
||||
|
||||
if (duration < minimalWholeDayDuration) {
|
||||
endDateTime = DateTime.fromISO(startDateTime, { zone: timeZone }).plus({ hours: 24 }).toISO();
|
||||
}
|
||||
}
|
||||
|
||||
const body: IDataObject = {
|
||||
...additionalFields,
|
||||
};
|
||||
|
||||
if (startDateTime) {
|
||||
body.start = {
|
||||
dateTime: startDateTime,
|
||||
timeZone,
|
||||
};
|
||||
}
|
||||
|
||||
if (endDateTime) {
|
||||
body.end = {
|
||||
dateTime: endDateTime,
|
||||
timeZone,
|
||||
};
|
||||
}
|
||||
|
||||
const endpoint = `/calendar/events/${eventId}`;
|
||||
|
||||
const responseData = await microsoftApiRequest.call(this, 'PATCH', endpoint, body);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
Reference in New Issue
Block a user