Skip to content

The open alternative to Salesforce, designed for AI.

[reconnect account] Reseting calendar status and stage on reconnect (#12061)

Guillim411cb33137c3
diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
index 74675a75c44..742e77dca51 100644
--- a/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
@@ -20,6 +20,7 @@ import {
CalendarEventListFetchJobData,
} from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-event-list-fetch.job';
import {
+ CalendarChannelSyncStage,
CalendarChannelVisibility,
CalendarChannelWorkspaceEntity,
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
@@ -305,6 +306,46 @@ export class GoogleAPIsService {
})),
workspaceId,
});
+
+ const calendarChannels = await calendarChannelRepository.find({
+ where: { connectedAccountId: newOrExistingConnectedAccountId },
+ });
+
+ const calendarChannelUpdates = await calendarChannelRepository.update(
+ {
+ connectedAccountId: newOrExistingConnectedAccountId,
+ },
+ {
+ syncStage:
+ CalendarChannelSyncStage.FULL_CALENDAR_EVENT_LIST_FETCH_PENDING,
+ syncStatus: null,
+ syncCursor: '',
+ syncStageStartedAt: null,
+ },
+ manager,
+ );
+
+ const calendarChannelMetadata =
+ await this.objectMetadataRepository.findOneOrFail({
+ where: { nameSingular: 'calendarChannel', workspaceId },
+ });
+
+ this.workspaceEventEmitter.emitDatabaseBatchEvent({
+ objectMetadataNameSingular: 'calendarChannel',
+ action: DatabaseEventAction.UPDATED,
+ events: calendarChannels.map((calendarChannel) => ({
+ recordId: calendarChannel.id,
+ objectMetadata: calendarChannelMetadata,
+ properties: {
+ before: calendarChannel,
+ after: {
+ ...calendarChannel,
+ ...calendarChannelUpdates.raw[0],
+ },
+ },
+ })),
+ workspaceId,
+ });
}
},
);
diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/microsoft-apis.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/microsoft-apis.service.ts
index abda6711d26..1e908595c08 100644
--- a/packages/twenty-server/src/engine/core-modules/auth/services/microsoft-apis.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/auth/services/microsoft-apis.service.ts
@@ -20,6 +20,7 @@ import {
CalendarEventListFetchJobData,
} from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-event-list-fetch.job';
import {
+ CalendarChannelSyncStage,
CalendarChannelVisibility,
CalendarChannelWorkspaceEntity,
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
@@ -333,6 +334,47 @@ export class MicrosoftAPIsService {
})),
workspaceId,
});
+
+ // now for the calendar channels
+ const calendarChannels = await calendarChannelRepository.find({
+ where: { connectedAccountId: newOrExistingConnectedAccountId },
+ });
+
+ const calendarChannelUpdates = await calendarChannelRepository.update(
+ {
+ connectedAccountId: newOrExistingConnectedAccountId,
+ },
+ {
+ syncStage:
+ CalendarChannelSyncStage.FULL_CALENDAR_EVENT_LIST_FETCH_PENDING,
+ syncStatus: null,
+ syncCursor: '',
+ syncStageStartedAt: null,
+ },
+ manager,
+ );
+
+ const calendarChannelMetadata =
+ await this.objectMetadataRepository.findOneOrFail({
+ where: { nameSingular: 'calendarChannel', workspaceId },
+ });
+
+ this.workspaceEventEmitter.emitDatabaseBatchEvent({
+ objectMetadataNameSingular: 'calendarChannel',
+ action: DatabaseEventAction.UPDATED,
+ events: calendarChannels.map((calendarChannel) => ({
+ recordId: calendarChannel.id,
+ objectMetadata: calendarChannelMetadata,
+ properties: {
+ before: calendarChannel,
+ after: {
+ ...calendarChannel,
+ ...calendarChannelUpdates.raw[0],
+ },
+ },
+ })),
+ workspaceId,
+ });
}
},
);