4489 timebox finish google calendar full sync (#4615)

* add lodash differenceWith

* add awaits

* update sync cursor is working

* add logs

* use isSyncEnabled information to enqueue jobs

* add decorator InjectObjectMetadataRepository

* fix gmail-full-sync
This commit is contained in:
bosiraphael
2024-03-22 18:10:55 +01:00
committed by GitHub
parent 41aae5bd20
commit 5665656b05
7 changed files with 176 additions and 56 deletions

View File

@ -28,36 +28,18 @@ export class CalendarChannelRepository {
);
}
public async getFirstByConnectedAccountIdOrFail(
public async getFirstByConnectedAccountId(
connectedAccountId: string,
workspaceId: string,
): Promise<ObjectRecord<CalendarChannelObjectMetadata>> {
): Promise<ObjectRecord<CalendarChannelObjectMetadata> | undefined> {
const calendarChannels = await this.getByConnectedAccountId(
connectedAccountId,
workspaceId,
);
if (!calendarChannels || calendarChannels.length === 0) {
throw new Error(
`No calendar channel found for connected account ${connectedAccountId} in workspace ${workspaceId}`,
);
}
return calendarChannels[0];
}
public async getIsContactAutoCreationEnabledByConnectedAccountIdOrFail(
connectedAccountId: string,
workspaceId: string,
): Promise<boolean> {
const calendarChannel = await this.getFirstByConnectedAccountIdOrFail(
connectedAccountId,
workspaceId,
);
return calendarChannel.isContactAutoCreationEnabled;
}
public async getByIds(
ids: string[],
workspaceId: string,
@ -73,4 +55,21 @@ export class CalendarChannelRepository {
transactionManager,
);
}
public async updateSyncCursor(
syncCursor: string,
calendarChannelId: string,
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."calendarChannel" SET "syncCursor" = $1 WHERE "id" = $2`,
[syncCursor, calendarChannelId],
workspaceId,
transactionManager,
);
}
}