mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +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:
@@ -21,6 +21,11 @@ import {
|
||||
eventOperations,
|
||||
} from './EventDescription';
|
||||
|
||||
import {
|
||||
freeBusyFields,
|
||||
freeBusyOperations,
|
||||
} from './freeBusyDescription';
|
||||
|
||||
import {
|
||||
IEvent,
|
||||
} from './EventInterface';
|
||||
@@ -60,12 +65,18 @@ export class GoogleCalendar implements INodeType {
|
||||
name: 'Event',
|
||||
value: 'event',
|
||||
},
|
||||
{
|
||||
name: 'Freebusy',
|
||||
value: 'freeBusy',
|
||||
},
|
||||
],
|
||||
default: 'event',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
...eventOperations,
|
||||
...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)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else if (responseData !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user