mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 03:42:16 +00:00
⚡ Add Google Calendar availability (#1105)
* ⚡ Add Feebusy resource to the Google Calendar node * ⚡ Improvements Co-authored-by: Harshil <ghagrawal17@gmail.com>
This commit is contained in:
@@ -51,7 +51,7 @@ export const eventFields = [
|
|||||||
/* event:create */
|
/* event:create */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Calendar',
|
displayName: 'Calendar ID',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
@@ -453,7 +453,7 @@ export const eventFields = [
|
|||||||
/* event:delete */
|
/* event:delete */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Calendar',
|
displayName: 'Calendar ID',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
@@ -536,7 +536,7 @@ export const eventFields = [
|
|||||||
/* event:get */
|
/* event:get */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Calendar',
|
displayName: 'Calendar ID',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
@@ -613,7 +613,7 @@ export const eventFields = [
|
|||||||
/* event:getAll */
|
/* event:getAll */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Calendar',
|
displayName: 'Calendar ID',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
@@ -791,7 +791,7 @@ export const eventFields = [
|
|||||||
/* event:update */
|
/* event:update */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Calendar',
|
displayName: 'Calendar ID',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
|||||||
132
packages/nodes-base/nodes/Google/Calendar/FreebusyDescription.ts
Normal file
132
packages/nodes-base/nodes/Google/Calendar/FreebusyDescription.ts
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import {
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const freeBusyOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get',
|
||||||
|
value: 'get',
|
||||||
|
description: 'Returns free/busy information for a calendar',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'get',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const freeBusyFields = [
|
||||||
|
{
|
||||||
|
displayName: 'Calendar ID',
|
||||||
|
name: 'calendarId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getCalendars',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Time Min.',
|
||||||
|
name: 'timeMin',
|
||||||
|
type: 'dateTime',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Start of the interval',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Time Max.',
|
||||||
|
name: 'timeMax',
|
||||||
|
type: 'dateTime',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'End of the interval',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Simple',
|
||||||
|
name: 'simple',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: true,
|
||||||
|
description: 'When set to true a simplify version of the response will be used else the raw data.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'freeBusy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Timezone',
|
||||||
|
name: 'timezone',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getTimezones',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Time zone used in the response. By default n8n timezone is used.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
@@ -21,6 +21,11 @@ import {
|
|||||||
eventOperations,
|
eventOperations,
|
||||||
} from './EventDescription';
|
} from './EventDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
freeBusyFields,
|
||||||
|
freeBusyOperations,
|
||||||
|
} from './freeBusyDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IEvent,
|
IEvent,
|
||||||
} from './EventInterface';
|
} from './EventInterface';
|
||||||
@@ -60,12 +65,18 @@ export class GoogleCalendar implements INodeType {
|
|||||||
name: 'Event',
|
name: 'Event',
|
||||||
value: 'event',
|
value: 'event',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Freebusy',
|
||||||
|
value: 'freeBusy',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
default: 'event',
|
default: 'event',
|
||||||
description: 'The resource to operate on.',
|
description: 'The resource to operate on.',
|
||||||
},
|
},
|
||||||
...eventOperations,
|
...eventOperations,
|
||||||
...eventFields,
|
...eventFields,
|
||||||
|
...freeBusyOperations,
|
||||||
|
...freeBusyFields,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -543,6 +554,47 @@ export class GoogleCalendar implements INodeType {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (resource === 'freeBusy') {
|
||||||
|
//https://developers.google.com/calendar/v3/reference/freebusy/query
|
||||||
|
if (operation === 'get') {
|
||||||
|
const timezone = this.getTimezone();
|
||||||
|
const calendarId = this.getNodeParameter('calendarId', i) as string;
|
||||||
|
const timeMin = this.getNodeParameter('timeMin', i) as string;
|
||||||
|
const timeMax = this.getNodeParameter('timeMax', i) as string;
|
||||||
|
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
const body: IDataObject = {
|
||||||
|
timeMin: moment.tz(timeMin, timezone).utc().format(),
|
||||||
|
timeMax: moment.tz(timeMax, timezone).utc().format(),
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
id: calendarId,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
timeZone: additionalFields.timezone || timezone,
|
||||||
|
};
|
||||||
|
|
||||||
|
responseData = await googleApiRequest.call(
|
||||||
|
this,
|
||||||
|
'POST',
|
||||||
|
`/calendar/v3/freeBusy`,
|
||||||
|
body,
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (responseData.calendars[calendarId].errors) {
|
||||||
|
let errors = responseData.calendars[calendarId].errors;
|
||||||
|
errors = errors.map((e: IDataObject) => e.reason);
|
||||||
|
throw new Error(
|
||||||
|
`Google Calendar error response: ${errors.join('|')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (simple) {
|
||||||
|
responseData = responseData.calendars[calendarId].busy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
} else if (responseData !== undefined) {
|
} else if (responseData !== undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user