Files
twenty/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-get-events.service.ts
bosiraphael f458322303 Refactor calendar to use new sync statuses and stages (#6141)
- Refactor calendar modules and some messaging modules to better
organize them by business rules and decouple them
- Work toward a common architecture for the different calendar providers
by introducing interfaces for the drivers
- Modify cron job to use the new sync statuses and stages
2024-07-08 17:01:06 +02:00

38 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { GoogleCalendarGetEventsService as GoogleCalendarGetCalendarEventsService } from 'src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/services/google-calendar-get-events.service';
import { CalendarEventWithParticipants } from 'src/modules/calendar/common/types/calendar-event';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
export type GetCalendarEventsResponse = {
calendarEvents: CalendarEventWithParticipants[];
nextSyncCursor: string;
};
@Injectable()
export class CalendarGetCalendarEventsService {
constructor(
private readonly googleCalendarGetCalendarEventsService: GoogleCalendarGetCalendarEventsService,
) {}
public async getCalendarEvents(
connectedAccount: Pick<
ConnectedAccountWorkspaceEntity,
'provider' | 'refreshToken' | 'id'
>,
syncCursor?: string,
): Promise<GetCalendarEventsResponse> {
switch (connectedAccount.provider) {
case 'google':
return this.googleCalendarGetCalendarEventsService.getCalendarEvents(
connectedAccount,
syncCursor,
);
default:
throw new Error(
`Provider ${connectedAccount.provider} is not supported.`,
);
}
}
}