4710 implement google calendar incremental sync (#4822)

Closes #4710
This commit is contained in:
bosiraphael
2024-04-10 15:53:14 +02:00
committed by GitHub
parent f1cc1c60e0
commit e7d146363c
20 changed files with 333 additions and 152 deletions

View File

@ -12,6 +12,21 @@ export class CalendarChannelRepository {
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
) {}
public async getAll(
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarChannelObjectMetadata>[]> {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
return await this.workspaceDataSourceService.executeRawQuery(
`SELECT * FROM ${dataSourceSchema}."calendarChannel"`,
[],
workspaceId,
transactionManager,
);
}
public async getByConnectedAccountId(
connectedAccountId: string,
workspaceId: string,

View File

@ -160,14 +160,14 @@ export class CalendarEventParticipantRepository {
);
}
public async updateCalendarEventParticipants(
public async updateCalendarEventParticipantsAndReturnNewOnes(
calendarEventParticipants: CalendarEventParticipant[],
iCalUIDCalendarEventIdMap: Map<string, string>,
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
): Promise<CalendarEventParticipant[]> {
if (calendarEventParticipants.length === 0) {
return;
return [];
}
const dataSourceSchema =
@ -189,6 +189,14 @@ export class CalendarEventParticipantRepository {
calendarEventParticipant.handle,
);
const newCalendarEventParticipants = differenceWith(
calendarEventParticipants,
existingCalendarEventParticipants,
(calendarEventParticipant, existingCalendarEventParticipant) =>
calendarEventParticipant.handle ===
existingCalendarEventParticipant.handle,
);
await this.deleteByIds(
calendarEventParticipantsToDelete.map(
(calendarEventParticipant) => calendarEventParticipant.id,
@ -227,6 +235,8 @@ export class CalendarEventParticipantRepository {
workspaceId,
transactionManager,
);
return newCalendarEventParticipants;
}
public async getWithoutPersonIdAndWorkspaceMemberId(

View File

@ -80,34 +80,36 @@ export class CalendarEventRepository {
}
public async getICalUIDCalendarEventIdMap(
iCalUIDs: string[],
calendarEventIds: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<Map<string, string>> {
if (iCalUIDs.length === 0) {
if (calendarEventIds.length === 0) {
return new Map();
}
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
const calendarEvents: {
id: string;
iCalUID: string;
}[] = await this.workspaceDataSourceService.executeRawQuery(
`SELECT id, "iCalUID" FROM ${dataSourceSchema}."calendarEvent" WHERE "iCalUID" = ANY($1)`,
[iCalUIDs],
const calendarEvents:
| {
id: string;
iCalUID: string;
}[]
| undefined = await this.workspaceDataSourceService.executeRawQuery(
`SELECT id, "iCalUID" FROM ${dataSourceSchema}."calendarEvent" WHERE "id" = ANY($1)`,
[calendarEventIds],
workspaceId,
transactionManager,
);
const iCalUIDsCalendarEvnetIdsMap = new Map<string, string>();
const iCalUIDsCalendarEventIdsMap = new Map<string, string>();
calendarEvents.forEach((calendarEvent) => {
iCalUIDsCalendarEvnetIdsMap.set(calendarEvent.iCalUID, calendarEvent.id);
calendarEvents?.forEach((calendarEvent) => {
iCalUIDsCalendarEventIdsMap.set(calendarEvent.iCalUID, calendarEvent.id);
});
return iCalUIDsCalendarEvnetIdsMap;
return iCalUIDsCalendarEventIdsMap;
}
public async saveCalendarEvents(