mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -08:00
feat(Google Calendar Trigger Node): Add support for cancelled events (#7436)
Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/google-calendar-trigger-deleted-events/10612 This PR adds support for triggering workflows when Google Calendar events are cancelled.
This commit is contained in:
parent
57c609384a
commit
9d241a0d6d
|
@ -7,10 +7,10 @@ import type {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import { getCalendars, googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
|
||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
|
import { getCalendars, googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
||||||
|
|
||||||
export class GoogleCalendarTrigger implements INodeType {
|
export class GoogleCalendarTrigger implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Google Calendar Trigger',
|
displayName: 'Google Calendar Trigger',
|
||||||
|
@ -81,6 +81,10 @@ export class GoogleCalendarTrigger implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Event Cancelled',
|
||||||
|
value: 'eventCancelled',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Event Created',
|
name: 'Event Created',
|
||||||
value: 'eventCreated',
|
value: 'eventCreated',
|
||||||
|
@ -160,10 +164,15 @@ export class GoogleCalendarTrigger implements INodeType {
|
||||||
|
|
||||||
let events;
|
let events;
|
||||||
|
|
||||||
if (triggerOn === 'eventCreated' || triggerOn === 'eventUpdated') {
|
if (
|
||||||
|
triggerOn === 'eventCreated' ||
|
||||||
|
triggerOn === 'eventUpdated' ||
|
||||||
|
triggerOn === 'eventCancelled'
|
||||||
|
) {
|
||||||
Object.assign(qs, {
|
Object.assign(qs, {
|
||||||
updatedMin: startDate,
|
updatedMin: startDate,
|
||||||
orderBy: 'updated',
|
orderBy: 'updated',
|
||||||
|
showDeleted: triggerOn === 'eventCancelled',
|
||||||
});
|
});
|
||||||
} else if (triggerOn === 'eventStarted' || triggerOn === 'eventEnded') {
|
} else if (triggerOn === 'eventStarted' || triggerOn === 'eventEnded') {
|
||||||
Object.assign(qs, {
|
Object.assign(qs, {
|
||||||
|
@ -201,13 +210,16 @@ export class GoogleCalendarTrigger implements INodeType {
|
||||||
events = events.filter((event: { created: string }) =>
|
events = events.filter((event: { created: string }) =>
|
||||||
moment(event.created).isBetween(startDate, endDate),
|
moment(event.created).isBetween(startDate, endDate),
|
||||||
);
|
);
|
||||||
} else if (triggerOn === 'eventUpdated') {
|
} else if (triggerOn === 'eventUpdated' || triggerOn === 'eventCancelled') {
|
||||||
events = events.filter(
|
events = events.filter(
|
||||||
(event: { created: string; updated: string }) =>
|
(event: { created: string; updated: string }) =>
|
||||||
!moment(moment(event.created).format('YYYY-MM-DDTHH:mm:ss')).isSame(
|
!moment(moment(event.created).format('YYYY-MM-DDTHH:mm:ss')).isSame(
|
||||||
moment(event.updated).format('YYYY-MM-DDTHH:mm:ss'),
|
moment(event.updated).format('YYYY-MM-DDTHH:mm:ss'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (triggerOn === 'eventCancelled') {
|
||||||
|
events = events.filter((event: { status: string }) => event.status === 'cancelled');
|
||||||
|
}
|
||||||
} else if (triggerOn === 'eventStarted') {
|
} else if (triggerOn === 'eventStarted') {
|
||||||
events = events.filter((event: { start: { dateTime: string } }) =>
|
events = events.filter((event: { start: { dateTime: string } }) =>
|
||||||
moment(event.start.dateTime).isBetween(startDate, endDate, null, '[]'),
|
moment(event.start.dateTime).isBetween(startDate, endDate, null, '[]'),
|
||||||
|
|
Loading…
Reference in a new issue