From f8dd2cc733ec33b6a6c4a55a5abfe694613d0cef Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Tue, 2 Jul 2024 13:55:11 +0200 Subject: [PATCH] Reorganise calendar module (#6089) Refactor Calendar into functional sub modules image --------- Co-authored-by: bosiraphael --- .../src/command/command.module.ts | 5 -- .../workspace/calendar-channel.ts | 2 +- .../workspace/calendar-event-participants.ts | 2 +- .../workspace-query-hook.module.ts | 2 +- .../engine/core-modules/auth/auth.module.ts | 2 +- .../auth/services/google-apis.service.ts | 28 +++----- .../auth/types/google-api-request.type.ts | 2 +- ...apis-set-request-extra-params.util.spec.ts | 2 +- .../dtos/timeline-calendar-event.dto.ts | 2 +- .../timeline-calendar-event.module.ts | 2 +- .../timeline-calendar-event.service.ts | 4 +- .../integrations/message-queue/jobs.module.ts | 8 +-- .../standard-objects/index.ts | 8 +-- ...lendar-messaging-participant-job.module.ts | 2 +- .../jobs/match-participant.job.ts | 2 +- .../jobs/unmatch-participant.job.ts | 2 +- .../calendar-blocklist-manager.module.ts | 18 +++++ ...ocklist-item-delete-calendar-events.job.ts | 6 +- .../blocklist-reimport-calendar-events.job.ts | 6 +- .../listeners/calendar-blocklist.listener.ts | 4 +- .../calendar-event-cleaner.module.ts | 10 ++- ...ed-account-associated-calendar-data.job.ts | 2 +- .../calendar-event-cleaner.service.ts | 2 +- .../calendar-event-import-manager.module.ts} | 38 ++++++---- .../calendar-events-import.cron.command.ts} | 14 ++-- .../jobs/calendar-events-import.cron.job.ts | 72 +++++++++++++++++++ .../google-calendar-driver.module.ts} | 4 +- .../providers}/google-calendar.provider.ts | 0 .../jobs/calendar-events-import.job.ts} | 16 ++--- .../calendar-events-import.service.ts} | 26 +++---- .../filter-out-blocklisted-events.util.ts | 0 .../format-google-calendar-event.util.ts | 4 +- ...-values-string-for-batch-raw-query.util.ts | 0 .../calendar-event-participant.module.ts | 17 ++++- .../calendar-event-participant.listener.ts | 2 +- .../calendar-event-participant.service.ts | 6 +- .../src/modules/calendar/calendar.module.ts | 27 +++---- .../commands/calendar-commands.module.ts | 10 --- .../commands/google-calendar-sync.command.ts | 40 ----------- ...calendar-event-find-many.pre-query.hook.ts | 4 +- .../calendar-event-find-one.pre-query-hook.ts | 4 +- .../can-access-calendar-event.service.ts | 10 +-- .../query-hooks/calendar-query-hook.module.ts | 10 +-- ...nnel-event-association.workspace-entity.ts | 4 +- .../calendar-channel.workspace-entity.ts | 2 +- ...ndar-event-participant.workspace-entity.ts | 2 +- .../calendar-event.workspace-entity.ts | 4 +- .../{ => common}/types/calendar-event.ts | 4 +- .../commands/calendar-cron-commands.module.ts | 8 --- .../crons/jobs/calendar-cron-job.module.ts | 19 ----- .../jobs/google-calendar-sync.cron.job.ts | 46 ------------ .../calendar/jobs/calendar-job.module.ts | 45 ------------ .../workspace-google-calendar-sync.module.ts | 12 ---- .../workspace-google-calendar-sync.service.ts | 45 ------------ .../google-calendar-search-filter.util.ts | 9 --- ...-companies-and-contacts-creation.module.ts | 4 +- ...cts-creation-calendar-channel.listener.ts} | 6 +- .../create-company-and-contact.service.ts | 4 +- .../connected-account.workspace-entity.ts | 2 +- .../messaging-message-participant.service.ts | 2 +- ...sage-cleaner-connected-account.listener.ts | 8 +-- ...eate-company-and-contact-after-sync.job.ts | 4 +- .../messaging-participants-manager.module.ts | 5 ++ .../person/repositories/person.repository.ts | 2 +- .../person.workspace-entity.ts | 2 +- .../workspace-member.workspace-entity.ts | 2 +- 66 files changed, 267 insertions(+), 401 deletions(-) create mode 100644 packages/twenty-server/src/modules/calendar/blocklist-manager/calendar-blocklist-manager.module.ts rename packages/twenty-server/src/modules/calendar/{ => blocklist-manager}/jobs/blocklist-item-delete-calendar-events.job.ts (94%) rename packages/twenty-server/src/modules/calendar/{ => blocklist-manager}/jobs/blocklist-reimport-calendar-events.job.ts (88%) rename packages/twenty-server/src/modules/calendar/{ => blocklist-manager}/listeners/calendar-blocklist.listener.ts (93%) rename packages/twenty-server/src/modules/calendar/{services => }/calendar-event-cleaner/calendar-event-cleaner.module.ts (51%) rename packages/twenty-server/src/modules/calendar/{ => calendar-event-cleaner}/jobs/delete-connected-account-associated-calendar-data.job.ts (95%) rename packages/twenty-server/src/modules/calendar/{services/calendar-event-cleaner => calendar-event-cleaner/services}/calendar-event-cleaner.service.ts (95%) rename packages/twenty-server/src/modules/calendar/{services/google-calendar-sync/google-calendar-sync.module.ts => calendar-event-import-manager/calendar-event-import-manager.module.ts} (50%) rename packages/twenty-server/src/modules/calendar/{crons/commands/google-calendar-sync.cron.command.ts => calendar-event-import-manager/crons/commands/calendar-events-import.cron.command.ts} (58%) create mode 100644 packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job.ts rename packages/twenty-server/src/modules/calendar/{services/providers/calendar-providers.module.ts => calendar-event-import-manager/drivers/google-calendar/google-calendar-driver.module.ts} (77%) rename packages/twenty-server/src/modules/calendar/{services/providers/google-calendar => calendar-event-import-manager/drivers/google-calendar/providers}/google-calendar.provider.ts (100%) rename packages/twenty-server/src/modules/calendar/{jobs/google-calendar-sync.job.ts => calendar-event-import-manager/jobs/calendar-events-import.job.ts} (80%) rename packages/twenty-server/src/modules/calendar/{services/google-calendar-sync/google-calendar-sync.service.ts => calendar-event-import-manager/services/calendar-events-import.service.ts} (95%) rename packages/twenty-server/src/modules/calendar/{ => calendar-event-import-manager}/utils/filter-out-blocklisted-events.util.ts (100%) rename packages/twenty-server/src/modules/calendar/{ => calendar-event-import-manager}/utils/format-google-calendar-event.util.ts (94%) rename packages/twenty-server/src/modules/calendar/{ => calendar-event-import-manager}/utils/get-flattened-values-and-values-string-for-batch-raw-query.util.ts (100%) rename packages/twenty-server/src/modules/calendar/{services/calendar-event-participant => calendar-event-participant-manager}/calendar-event-participant.module.ts (58%) rename packages/twenty-server/src/modules/calendar/{ => calendar-event-participant-manager}/listeners/calendar-event-participant.listener.ts (97%) rename packages/twenty-server/src/modules/calendar/{services/calendar-event-participant => calendar-event-participant-manager/services}/calendar-event-participant.service.ts (95%) delete mode 100644 packages/twenty-server/src/modules/calendar/commands/calendar-commands.module.ts delete mode 100644 packages/twenty-server/src/modules/calendar/commands/google-calendar-sync.command.ts rename packages/twenty-server/src/modules/calendar/{ => common}/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts (92%) rename packages/twenty-server/src/modules/calendar/{ => common}/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts (92%) rename packages/twenty-server/src/modules/calendar/{ => common}/query-hooks/calendar-event/services/can-access-calendar-event.service.ts (94%) rename packages/twenty-server/src/modules/calendar/{ => common}/query-hooks/calendar-query-hook.module.ts (75%) rename packages/twenty-server/src/modules/calendar/{ => common}/standard-objects/calendar-channel-event-association.workspace-entity.ts (96%) rename packages/twenty-server/src/modules/calendar/{ => common}/standard-objects/calendar-channel.workspace-entity.ts (99%) rename packages/twenty-server/src/modules/calendar/{ => common}/standard-objects/calendar-event-participant.workspace-entity.ts (98%) rename packages/twenty-server/src/modules/calendar/{ => common}/standard-objects/calendar-event.workspace-entity.ts (97%) rename packages/twenty-server/src/modules/calendar/{ => common}/types/calendar-event.ts (85%) delete mode 100644 packages/twenty-server/src/modules/calendar/crons/commands/calendar-cron-commands.module.ts delete mode 100644 packages/twenty-server/src/modules/calendar/crons/jobs/calendar-cron-job.module.ts delete mode 100644 packages/twenty-server/src/modules/calendar/crons/jobs/google-calendar-sync.cron.job.ts delete mode 100644 packages/twenty-server/src/modules/calendar/jobs/calendar-job.module.ts delete mode 100644 packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module.ts delete mode 100644 packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service.ts delete mode 100644 packages/twenty-server/src/modules/calendar/utils/google-calendar-search-filter.util.ts rename packages/twenty-server/src/modules/{calendar/listeners/calendar-channel.listener.ts => connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts} (90%) rename packages/twenty-server/src/modules/{calendar => messaging/message-participants-manager}/jobs/calendar-create-company-and-contact-after-sync.job.ts (96%) diff --git a/packages/twenty-server/src/command/command.module.ts b/packages/twenty-server/src/command/command.module.ts index 86c629f928..70fa379446 100644 --- a/packages/twenty-server/src/command/command.module.ts +++ b/packages/twenty-server/src/command/command.module.ts @@ -3,20 +3,15 @@ import { Module } from '@nestjs/common'; import { DatabaseCommandModule } from 'src/database/commands/database-command.module'; import { WorkspaceHealthCommandModule } from 'src/engine/workspace-manager/workspace-health/commands/workspace-health-command.module'; import { WorkspaceCleanerModule } from 'src/engine/workspace-manager/workspace-cleaner/workspace-cleaner.module'; -import { CalendarCronCommandsModule } from 'src/modules/calendar/crons/commands/calendar-cron-commands.module'; import { AppModule } from 'src/app.module'; import { WorkspaceMigrationRunnerCommandsModule } from 'src/engine/workspace-manager/workspace-migration-runner/commands/workspace-sync-metadata-commands.module'; import { WorkspaceSyncMetadataCommandsModule } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module'; -import { CalendarCommandsModule } from 'src/modules/calendar/commands/calendar-commands.module'; @Module({ imports: [ AppModule, WorkspaceSyncMetadataCommandsModule, DatabaseCommandModule, - // MessagingCronCommandsModule, - CalendarCronCommandsModule, - CalendarCommandsModule, WorkspaceCleanerModule, WorkspaceHealthCommandModule, WorkspaceMigrationRunnerCommandsModule, diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-channel.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-channel.ts index 1c217c07cf..14a4117ee3 100644 --- a/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-channel.ts +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-channel.ts @@ -1,7 +1,7 @@ import { EntityManager } from 'typeorm'; import { DEV_SEED_CONNECTED_ACCOUNT_IDS } from 'src/database/typeorm-seeds/workspace/connected-account'; -import { CalendarChannelVisibility } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; +import { CalendarChannelVisibility } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; const tableName = 'calendarChannel'; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-event-participants.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-event-participants.ts index 784ad55af8..4efc444061 100644 --- a/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-event-participants.ts +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/calendar-event-participants.ts @@ -2,7 +2,7 @@ import { EntityManager } from 'typeorm'; import { DEV_SEED_PERSON_IDS } from 'src/database/typeorm-seeds/workspace/people'; import { DEV_SEED_WORKSPACE_MEMBER_IDS } from 'src/database/typeorm-seeds/workspace/workspace-members'; -import { CalendarEventParticipantResponseStatus } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventParticipantResponseStatus } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; const tableName = 'calendarEventParticipant'; diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.module.ts b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.module.ts index f018238835..056e5073cd 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.module.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.module.ts @@ -5,7 +5,7 @@ import { WorkspaceQueryHookStorage } from 'src/engine/api/graphql/workspace-quer import { WorkspaceQueryHookMetadataAccessor } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook-metadata.accessor'; import { WorkspaceQueryHookExplorer } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.explorer'; import { WorkspaceQueryHookService } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.service'; -import { CalendarQueryHookModule } from 'src/modules/calendar/query-hooks/calendar-query-hook.module'; +import { CalendarQueryHookModule } from 'src/modules/calendar/common/query-hooks/calendar-query-hook.module'; import { ConnectedAccountQueryHookModule } from 'src/modules/connected-account/query-hooks/connected-account-query-hook.module'; import { MessagingQueryHookModule } from 'src/modules/messaging/common/query-hooks/messaging-query-hook.module'; import { WorkspaceMemberQueryHookModule } from 'src/modules/workspace-member/query-hooks/workspace-member-query-hook.module'; diff --git a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts index 53953bc94b..5f60af70e3 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts @@ -25,12 +25,12 @@ import { MicrosoftAuthController } from 'src/engine/core-modules/auth/controller import { AppTokenService } from 'src/engine/core-modules/app-token/services/app-token.service'; import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; import { OnboardingModule } from 'src/engine/core-modules/onboarding/onboarding.module'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; import { AuthResolver } from './auth.resolver'; 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 665dea7037..99f39f892f 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 @@ -7,14 +7,6 @@ import { EnvironmentService } from 'src/engine/integrations/environment/environm import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; -import { - GoogleCalendarSyncJobData, - GoogleCalendarSyncJob, -} from 'src/modules/calendar/jobs/google-calendar-sync.job'; -import { - CalendarChannelWorkspaceEntity, - CalendarChannelVisibility, -} from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; import { ConnectedAccountWorkspaceEntity, @@ -36,6 +28,14 @@ import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inje import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource'; import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator'; +import { + CalendarEventsImportJob, + CalendarEventsImportJobData, +} from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job'; +import { + CalendarChannelWorkspaceEntity, + CalendarChannelVisibility, +} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; @Injectable() export class GoogleAPIsService { @@ -166,19 +166,13 @@ export class GoogleAPIsService { } } - if ( - this.environmentService.get('CALENDAR_PROVIDER_GOOGLE_ENABLED') && - isCalendarEnabled - ) { - await this.calendarQueueService.add( - GoogleCalendarSyncJob.name, + if (isCalendarEnabled) { + await this.calendarQueueService.add( + CalendarEventsImportJob.name, { workspaceId, connectedAccountId: newOrExistingConnectedAccountId, }, - { - retryLimit: 2, - }, ); } } diff --git a/packages/twenty-server/src/engine/core-modules/auth/types/google-api-request.type.ts b/packages/twenty-server/src/engine/core-modules/auth/types/google-api-request.type.ts index 276de7941e..f8d5f609d4 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/types/google-api-request.type.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/types/google-api-request.type.ts @@ -1,6 +1,6 @@ import { Request } from 'express'; -import { CalendarChannelVisibility } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; +import { CalendarChannelVisibility } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; import { MessageChannelVisibility } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; export type GoogleAPIsRequest = Omit< diff --git a/packages/twenty-server/src/engine/core-modules/auth/utils/__tests__/google-apis-set-request-extra-params.util.spec.ts b/packages/twenty-server/src/engine/core-modules/auth/utils/__tests__/google-apis-set-request-extra-params.util.spec.ts index be7b92c0c6..052f4ff04d 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/utils/__tests__/google-apis-set-request-extra-params.util.spec.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/utils/__tests__/google-apis-set-request-extra-params.util.spec.ts @@ -1,6 +1,6 @@ import { GoogleAPIsRequest } from 'src/engine/core-modules/auth/types/google-api-request.type'; import { setRequestExtraParams } from 'src/engine/core-modules/auth/utils/google-apis-set-request-extra-params.util'; -import { CalendarChannelVisibility } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; +import { CalendarChannelVisibility } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; import { MessageChannelVisibility } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; describe('googleApisSetRequestExtraParams', () => { diff --git a/packages/twenty-server/src/engine/core-modules/calendar/dtos/timeline-calendar-event.dto.ts b/packages/twenty-server/src/engine/core-modules/calendar/dtos/timeline-calendar-event.dto.ts index 2c64d92261..c9e579ccd3 100644 --- a/packages/twenty-server/src/engine/core-modules/calendar/dtos/timeline-calendar-event.dto.ts +++ b/packages/twenty-server/src/engine/core-modules/calendar/dtos/timeline-calendar-event.dto.ts @@ -2,7 +2,7 @@ import { ObjectType, Field, registerEnumType } from '@nestjs/graphql'; import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars'; import { TimelineCalendarEventParticipant } from 'src/engine/core-modules/calendar/dtos/timeline-calendar-event-participant.dto'; -import { CalendarChannelVisibility } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; +import { CalendarChannelVisibility } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; registerEnumType(CalendarChannelVisibility, { name: 'CalendarChannelVisibility', diff --git a/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.module.ts b/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.module.ts index c8a7d442a0..47bdee1888 100644 --- a/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.module.ts +++ b/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.module.ts @@ -4,8 +4,8 @@ import { UserModule } from 'src/engine/core-modules/user/user.module'; import { TimelineCalendarEventResolver } from 'src/engine/core-modules/calendar/timeline-calendar-event.resolver'; import { TimelineCalendarEventService } from 'src/engine/core-modules/calendar/timeline-calendar-event.service'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; @Module({ imports: [ diff --git a/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts b/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts index 59013ab3d4..1ef6370abc 100644 --- a/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts +++ b/packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts @@ -7,9 +7,9 @@ import { TIMELINE_CALENDAR_EVENTS_DEFAULT_PAGE_SIZE } from 'src/engine/core-modu import { TimelineCalendarEventsWithTotal } from 'src/engine/core-modules/calendar/dtos/timeline-calendar-events-with-total.dto'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; -import { CalendarChannelVisibility } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; +import { CalendarChannelVisibility } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; @Injectable() export class TimelineCalendarEventService { diff --git a/packages/twenty-server/src/engine/integrations/message-queue/jobs.module.ts b/packages/twenty-server/src/engine/integrations/message-queue/jobs.module.ts index c2e7ecf092..eb107b3fba 100644 --- a/packages/twenty-server/src/engine/integrations/message-queue/jobs.module.ts +++ b/packages/twenty-server/src/engine/integrations/message-queue/jobs.module.ts @@ -16,16 +16,13 @@ import { EmailModule } from 'src/engine/integrations/email/email.module'; import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-source.module'; import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module'; import { CleanInactiveWorkspaceJob } from 'src/engine/workspace-manager/workspace-cleaner/crons/clean-inactive-workspace.job'; -import { CalendarEventParticipantModule } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module'; import { TimelineActivityModule } from 'src/modules/timeline/timeline-activity.module'; import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module'; -import { CalendarMessagingParticipantJobModule } from 'src/modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module'; -import { CalendarCronJobModule } from 'src/modules/calendar/crons/jobs/calendar-cron-job.module'; -import { CalendarJobModule } from 'src/modules/calendar/jobs/calendar-job.module'; import { AutoCompaniesAndContactsCreationJobModule } from 'src/modules/connected-account/auto-companies-and-contacts-creation/jobs/auto-companies-and-contacts-creation-job.module'; import { MessagingModule } from 'src/modules/messaging/messaging.module'; import { TimelineJobModule } from 'src/modules/timeline/jobs/timeline-job.module'; import { CalendarModule } from 'src/modules/calendar/calendar.module'; +import { CalendarEventParticipantModule } from 'src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module'; @Module({ imports: [ @@ -44,9 +41,6 @@ import { CalendarModule } from 'src/modules/calendar/calendar.module'; TimelineActivityModule, StripeModule, WorkspaceQueryRunnerJobModule, - CalendarMessagingParticipantJobModule, - CalendarCronJobModule, - CalendarJobModule, AutoCompaniesAndContactsCreationJobModule, TimelineJobModule, ], diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts index 39ef93760e..c56dcf41df 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts @@ -3,9 +3,6 @@ import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/a import { ApiKeyWorkspaceEntity } from 'src/modules/api-key/standard-objects/api-key.workspace-entity'; import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { CommentWorkspaceEntity } from 'src/modules/activity/standard-objects/comment.workspace-entity'; import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; @@ -18,7 +15,6 @@ import { ViewSortWorkspaceEntity } from 'src/modules/view/standard-objects/view- import { ViewWorkspaceEntity } from 'src/modules/view/standard-objects/view.workspace-entity'; import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; import { AuditLogWorkspaceEntity } from 'src/modules/timeline/standard-objects/audit-log.workspace-entity'; import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; import { BehavioralEventWorkspaceEntity } from 'src/modules/timeline/standard-objects/behavioral-event.workspace-entity'; @@ -27,6 +23,10 @@ import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/stan import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; import { MessageThreadWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-thread.workspace-entity'; import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; export const standardObjectMetadataDefinitions = [ ActivityTargetWorkspaceEntity, diff --git a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module.ts b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module.ts index 4208f5b3d5..d54066bbd8 100644 --- a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module.ts +++ b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module.ts @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common'; import { MatchParticipantJob } from 'src/modules/calendar-messaging-participant/jobs/match-participant.job'; import { UnmatchParticipantJob } from 'src/modules/calendar-messaging-participant/jobs/unmatch-participant.job'; -import { CalendarEventParticipantModule } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module'; +import { CalendarEventParticipantModule } from 'src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module'; import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module'; @Module({ diff --git a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/match-participant.job.ts b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/match-participant.job.ts index f8ccadfa44..f18b561a5e 100644 --- a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/match-participant.job.ts +++ b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/match-participant.job.ts @@ -3,7 +3,7 @@ import { Scope } from '@nestjs/common'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service'; +import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service'; import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service'; export type MatchParticipantJobData = { diff --git a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/unmatch-participant.job.ts b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/unmatch-participant.job.ts index a2b8c9044a..3579bc8b4a 100644 --- a/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/unmatch-participant.job.ts +++ b/packages/twenty-server/src/modules/calendar-messaging-participant/jobs/unmatch-participant.job.ts @@ -2,9 +2,9 @@ import { Scope } from '@nestjs/common'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service'; import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; +import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service'; export type UnmatchParticipantJobData = { workspaceId: string; diff --git a/packages/twenty-server/src/modules/calendar/blocklist-manager/calendar-blocklist-manager.module.ts b/packages/twenty-server/src/modules/calendar/blocklist-manager/calendar-blocklist-manager.module.ts new file mode 100644 index 0000000000..57497f1d27 --- /dev/null +++ b/packages/twenty-server/src/modules/calendar/blocklist-manager/calendar-blocklist-manager.module.ts @@ -0,0 +1,18 @@ +import { Module } from '@nestjs/common'; + +import { BlocklistItemDeleteCalendarEventsJob } from 'src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job'; +import { BlocklistReimportCalendarEventsJob } from 'src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job'; +import { CalendarBlocklistListener } from 'src/modules/calendar/blocklist-manager/listeners/calendar-blocklist.listener'; +import { CalendarEventCleanerModule } from 'src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module'; +import { CalendarEventImportManagerModule } from 'src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module'; + +@Module({ + imports: [CalendarEventCleanerModule, CalendarEventImportManagerModule], + providers: [ + CalendarBlocklistListener, + BlocklistItemDeleteCalendarEventsJob, + BlocklistReimportCalendarEventsJob, + ], + exports: [], +}) +export class CalendarBlocklistManagerModule {} diff --git a/packages/twenty-server/src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job.ts b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job.ts similarity index 94% rename from packages/twenty-server/src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job.ts rename to packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job.ts index 3af5c2a476..0087f61a8d 100644 --- a/packages/twenty-server/src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job.ts +++ b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job.ts @@ -5,14 +5,14 @@ import { Any, ILike } from 'typeorm'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; -import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; +import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; export type BlocklistItemDeleteCalendarEventsJobData = { workspaceId: string; diff --git a/packages/twenty-server/src/modules/calendar/jobs/blocklist-reimport-calendar-events.job.ts b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts similarity index 88% rename from packages/twenty-server/src/modules/calendar/jobs/blocklist-reimport-calendar-events.job.ts rename to packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts index 7c34e0898c..3e44a97616 100644 --- a/packages/twenty-server/src/modules/calendar/jobs/blocklist-reimport-calendar-events.job.ts +++ b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts @@ -3,10 +3,10 @@ import { Logger, Scope } from '@nestjs/common'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; -import { GoogleCalendarSyncService } from 'src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service'; import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; +import { CalendarEventsImportService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service'; export type BlocklistReimportCalendarEventsJobData = { workspaceId: string; @@ -24,7 +24,7 @@ export class BlocklistReimportCalendarEventsJob { constructor( @InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity) private readonly connectedAccountRepository: ConnectedAccountRepository, - private readonly googleCalendarSyncService: GoogleCalendarSyncService, + private readonly googleCalendarSyncService: CalendarEventsImportService, ) {} @Process(BlocklistReimportCalendarEventsJob.name) @@ -49,7 +49,7 @@ export class BlocklistReimportCalendarEventsJob { return; } - await this.googleCalendarSyncService.startGoogleCalendarSync( + await this.googleCalendarSyncService.processCalendarEventsImport( workspaceId, connectedAccount[0].id, handle, diff --git a/packages/twenty-server/src/modules/calendar/listeners/calendar-blocklist.listener.ts b/packages/twenty-server/src/modules/calendar/blocklist-manager/listeners/calendar-blocklist.listener.ts similarity index 93% rename from packages/twenty-server/src/modules/calendar/listeners/calendar-blocklist.listener.ts rename to packages/twenty-server/src/modules/calendar/blocklist-manager/listeners/calendar-blocklist.listener.ts index b34441c9a1..370ca2f6e6 100644 --- a/packages/twenty-server/src/modules/calendar/listeners/calendar-blocklist.listener.ts +++ b/packages/twenty-server/src/modules/calendar/blocklist-manager/listeners/calendar-blocklist.listener.ts @@ -10,11 +10,11 @@ import { MessageQueueService } from 'src/engine/integrations/message-queue/servi import { BlocklistItemDeleteCalendarEventsJobData, BlocklistItemDeleteCalendarEventsJob, -} from 'src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job'; +} from 'src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job'; import { BlocklistReimportCalendarEventsJobData, BlocklistReimportCalendarEventsJob, -} from 'src/modules/calendar/jobs/blocklist-reimport-calendar-events.job'; +} from 'src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; @Injectable() diff --git a/packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module.ts similarity index 51% rename from packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module.ts index 12f92a4ec8..50da276614 100644 --- a/packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module.ts @@ -1,12 +1,16 @@ import { Module } from '@nestjs/common'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; -import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; +import { DeleteConnectedAccountAssociatedCalendarDataJob } from 'src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job'; +import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; @Module({ imports: [TwentyORMModule.forFeature([CalendarEventWorkspaceEntity])], - providers: [CalendarEventCleanerService], + providers: [ + CalendarEventCleanerService, + DeleteConnectedAccountAssociatedCalendarDataJob, + ], exports: [CalendarEventCleanerService], }) export class CalendarEventCleanerModule {} diff --git a/packages/twenty-server/src/modules/calendar/jobs/delete-connected-account-associated-calendar-data.job.ts b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job.ts similarity index 95% rename from packages/twenty-server/src/modules/calendar/jobs/delete-connected-account-associated-calendar-data.job.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job.ts index bd8e5ab9e2..4818145955 100644 --- a/packages/twenty-server/src/modules/calendar/jobs/delete-connected-account-associated-calendar-data.job.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job.ts @@ -3,7 +3,7 @@ import { Logger } from '@nestjs/common'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service'; +import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service'; export type DeleteConnectedAccountAssociatedCalendarDataJobData = { workspaceId: string; diff --git a/packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service.ts similarity index 95% rename from packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service.ts index 77a347a0d6..0248957a61 100644 --- a/packages/twenty-server/src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service.ts @@ -4,8 +4,8 @@ import { Any, IsNull } from 'typeorm'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; import { deleteUsingPagination } from 'src/modules/messaging/message-cleaner/utils/delete-using-pagination.util'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; @Injectable() export class CalendarEventCleanerService { diff --git a/packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts similarity index 50% rename from packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.module.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts index 11017c7f4c..57cef3e135 100644 --- a/packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts @@ -1,18 +1,24 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; +import { BillingModule } from 'src/engine/core-modules/billing/billing.module'; import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; +import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity'; import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; -import { CalendarEventCleanerModule } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module'; -import { CalendarEventParticipantModule } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module'; -import { GoogleCalendarSyncService } from 'src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service'; -import { CalendarProvidersModule } from 'src/modules/calendar/services/providers/calendar-providers.module'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; +import { CalendarEventCleanerModule } from 'src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module'; +import { CalendarEventsImportCronCommand } from 'src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-events-import.cron.command'; +import { CalendarEventsImportCronJob } from 'src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job'; +import { GoogleCalendarDriverModule } from 'src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/google-calendar-driver.module'; +import { CalendarEventsImportJob } from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job'; +import { CalendarEventsImportService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service'; +import { CalendarEventParticipantModule } from 'src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; +import { GoogleAPIRefreshAccessTokenModule } from 'src/modules/connected-account/services/google-api-refresh-access-token/google-api-refresh-access-token.module'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; @@ -20,7 +26,6 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/sta @Module({ imports: [ - CalendarProvidersModule, TwentyORMModule.forFeature([ CalendarEventWorkspaceEntity, CalendarChannelWorkspaceEntity, @@ -35,10 +40,19 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/sta ]), CalendarEventParticipantModule, TypeOrmModule.forFeature([FeatureFlagEntity], 'core'), + TypeOrmModule.forFeature([DataSourceEntity], 'metadata'), WorkspaceDataSourceModule, CalendarEventCleanerModule, + GoogleCalendarDriverModule, + BillingModule, + GoogleAPIRefreshAccessTokenModule, ], - providers: [GoogleCalendarSyncService], - exports: [GoogleCalendarSyncService], + providers: [ + CalendarEventsImportService, + CalendarEventsImportCronJob, + CalendarEventsImportCronCommand, + CalendarEventsImportJob, + ], + exports: [CalendarEventsImportService], }) -export class GoogleCalendarSyncModule {} +export class CalendarEventImportManagerModule {} diff --git a/packages/twenty-server/src/modules/calendar/crons/commands/google-calendar-sync.cron.command.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-events-import.cron.command.ts similarity index 58% rename from packages/twenty-server/src/modules/calendar/crons/commands/google-calendar-sync.cron.command.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-events-import.cron.command.ts index 3d0c110ad6..df8a47f16d 100644 --- a/packages/twenty-server/src/modules/calendar/crons/commands/google-calendar-sync.cron.command.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-events-import.cron.command.ts @@ -3,15 +3,15 @@ import { Command, CommandRunner } from 'nest-commander'; import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; -import { GoogleCalendarSyncCronJob } from 'src/modules/calendar/crons/jobs/google-calendar-sync.cron.job'; +import { CalendarEventsImportCronJob } from 'src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job'; -const GOOGLE_CALENDAR_SYNC_CRON_PATTERN = '*/5 * * * *'; +const CALENDAR_EVENTS_IMPORT_CRON_PATTERN = '*/5 * * * *'; @Command({ - name: 'cron:calendar:google-calendar-sync', - description: 'Starts a cron job to sync google calendar for all workspaces.', + name: 'cron:calendar:calendar-events-import', + description: 'Starts a cron job to import calendar events', }) -export class GoogleCalendarSyncCronCommand extends CommandRunner { +export class CalendarEventsImportCronCommand extends CommandRunner { constructor( @InjectMessageQueue(MessageQueue.cronQueue) private readonly messageQueueService: MessageQueueService, @@ -21,10 +21,10 @@ export class GoogleCalendarSyncCronCommand extends CommandRunner { async run(): Promise { await this.messageQueueService.addCron( - GoogleCalendarSyncCronJob.name, + CalendarEventsImportCronJob.name, undefined, { - repeat: { pattern: GOOGLE_CALENDAR_SYNC_CRON_PATTERN }, + repeat: { pattern: CALENDAR_EVENTS_IMPORT_CRON_PATTERN }, }, ); } diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job.ts new file mode 100644 index 0000000000..261bed6a75 --- /dev/null +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/crons/jobs/calendar-events-import.cron.job.ts @@ -0,0 +1,72 @@ +import { InjectRepository } from '@nestjs/typeorm'; +import { Scope } from '@nestjs/common'; + +import { Repository, In } from 'typeorm'; + +import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity'; +import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; +import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; +import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; +import { + CalendarEventsImportJobData, + CalendarEventsImportJob, +} from 'src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job'; +import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; +import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; +import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; +import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; +import { BillingService } from 'src/engine/core-modules/billing/billing.service'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; + +@Processor({ + queueName: MessageQueue.cronQueue, + scope: Scope.REQUEST, +}) +export class CalendarEventsImportCronJob { + constructor( + @InjectRepository(DataSourceEntity, 'metadata') + private readonly dataSourceRepository: Repository, + @InjectWorkspaceRepository(CalendarChannelWorkspaceEntity) + private readonly calendarChannelRepository: WorkspaceRepository, + @InjectMessageQueue(MessageQueue.calendarQueue) + private readonly messageQueueService: MessageQueueService, + private readonly billingService: BillingService, + ) {} + + @Process(CalendarEventsImportCronJob.name) + async handle(): Promise { + const workspaceIds = + await this.billingService.getActiveSubscriptionWorkspaceIds(); + + const dataSources = await this.dataSourceRepository.find({ + where: { + workspaceId: In(workspaceIds), + }, + }); + + const workspaceIdsWithDataSources = new Set( + dataSources.map((dataSource) => dataSource.workspaceId), + ); + + for (const workspaceId of workspaceIdsWithDataSources) { + const calendarChannels = await this.calendarChannelRepository.find({}); + + for (const calendarChannel of calendarChannels) { + if (!calendarChannel?.isSyncEnabled) { + continue; + } + + await this.messageQueueService.add( + CalendarEventsImportJob.name, + { + workspaceId, + connectedAccountId: calendarChannel.connectedAccount.id, + }, + { + retryLimit: 2, + }, + ); + } + } + } +} diff --git a/packages/twenty-server/src/modules/calendar/services/providers/calendar-providers.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/google-calendar-driver.module.ts similarity index 77% rename from packages/twenty-server/src/modules/calendar/services/providers/calendar-providers.module.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/google-calendar-driver.module.ts index c1309c85f3..e922cb11af 100644 --- a/packages/twenty-server/src/modules/calendar/services/providers/calendar-providers.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/google-calendar-driver.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; import { EnvironmentModule } from 'src/engine/integrations/environment/environment.module'; -import { GoogleCalendarClientProvider } from 'src/modules/calendar/services/providers/google-calendar/google-calendar.provider'; +import { GoogleCalendarClientProvider } from 'src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/providers/google-calendar.provider'; import { OAuth2ClientManagerModule } from 'src/modules/connected-account/oauth2-client-manager/oauth2-client-manager.module'; @Module({ @@ -9,4 +9,4 @@ import { OAuth2ClientManagerModule } from 'src/modules/connected-account/oauth2- providers: [GoogleCalendarClientProvider], exports: [GoogleCalendarClientProvider], }) -export class CalendarProvidersModule {} +export class GoogleCalendarDriverModule {} diff --git a/packages/twenty-server/src/modules/calendar/services/providers/google-calendar/google-calendar.provider.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/providers/google-calendar.provider.ts similarity index 100% rename from packages/twenty-server/src/modules/calendar/services/providers/google-calendar/google-calendar.provider.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/providers/google-calendar.provider.ts diff --git a/packages/twenty-server/src/modules/calendar/jobs/google-calendar-sync.job.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job.ts similarity index 80% rename from packages/twenty-server/src/modules/calendar/jobs/google-calendar-sync.job.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job.ts index b14dfd99a7..c20fef8ac7 100644 --- a/packages/twenty-server/src/modules/calendar/jobs/google-calendar-sync.job.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/jobs/calendar-events-import.job.ts @@ -1,15 +1,15 @@ import { Logger, Scope } from '@nestjs/common'; import { GoogleAPIRefreshAccessTokenService } from 'src/modules/connected-account/services/google-api-refresh-access-token/google-api-refresh-access-token.service'; -import { GoogleCalendarSyncService } from 'src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; +import { CalendarEventsImportService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service'; -export type GoogleCalendarSyncJobData = { +export type CalendarEventsImportJobData = { workspaceId: string; connectedAccountId: string; }; @@ -18,18 +18,18 @@ export type GoogleCalendarSyncJobData = { queueName: MessageQueue.calendarQueue, scope: Scope.REQUEST, }) -export class GoogleCalendarSyncJob { - private readonly logger = new Logger(GoogleCalendarSyncJob.name); +export class CalendarEventsImportJob { + private readonly logger = new Logger(CalendarEventsImportJob.name); constructor( private readonly googleAPIsRefreshAccessTokenService: GoogleAPIRefreshAccessTokenService, - private readonly googleCalendarSyncService: GoogleCalendarSyncService, + private readonly googleCalendarSyncService: CalendarEventsImportService, @InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity) private readonly connectedAccountRepository: ConnectedAccountRepository, ) {} - @Process(GoogleCalendarSyncJob.name) - async handle(data: GoogleCalendarSyncJobData): Promise { + @Process(CalendarEventsImportJob.name) + async handle(data: CalendarEventsImportJobData): Promise { this.logger.log( `google calendar sync for workspace ${data.workspaceId} and account ${data.connectedAccountId}`, ); @@ -60,7 +60,7 @@ export class GoogleCalendarSyncJob { return; } - await this.googleCalendarSyncService.startGoogleCalendarSync( + await this.googleCalendarSyncService.processCalendarEventsImport( data.workspaceId, data.connectedAccountId, ); diff --git a/packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service.ts similarity index 95% rename from packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service.ts index da819a40c1..3dc89de254 100644 --- a/packages/twenty-server/src/modules/calendar/services/google-calendar-sync/google-calendar-sync.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service.ts @@ -12,22 +12,14 @@ import { FeatureFlagEntity, FeatureFlagKeys, } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; -import { GoogleCalendarClientProvider } from 'src/modules/calendar/services/providers/google-calendar/google-calendar.provider'; -import { formatGoogleCalendarEvent } from 'src/modules/calendar/utils/format-google-calendar-event.util'; +import { formatGoogleCalendarEvent } from 'src/modules/calendar/calendar-event-import-manager/utils/format-google-calendar-event.util'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; -import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service'; -import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service'; import { CalendarEventParticipant, CalendarEventWithParticipants, -} from 'src/modules/calendar/types/calendar-event'; -import { filterOutBlocklistedEvents } from 'src/modules/calendar/utils/filter-out-blocklisted-events.util'; +} from 'src/modules/calendar/common/types/calendar-event'; import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; @@ -40,10 +32,18 @@ import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace. import { isDefined } from 'src/utils/is-defined'; import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource'; import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator'; +import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service'; +import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service'; +import { GoogleCalendarClientProvider } from 'src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/providers/google-calendar.provider'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; +import { filterOutBlocklistedEvents } from 'src/modules/calendar/calendar-event-import-manager/utils/filter-out-blocklisted-events.util'; @Injectable() -export class GoogleCalendarSyncService { - private readonly logger = new Logger(GoogleCalendarSyncService.name); +export class CalendarEventsImportService { + private readonly logger = new Logger(CalendarEventsImportService.name); constructor( private readonly googleCalendarClientProvider: GoogleCalendarClientProvider, @@ -70,7 +70,7 @@ export class GoogleCalendarSyncService { private readonly eventEmitter: EventEmitter2, ) {} - public async startGoogleCalendarSync( + public async processCalendarEventsImport( workspaceId: string, connectedAccountId: string, emailOrDomainToReimport?: string, diff --git a/packages/twenty-server/src/modules/calendar/utils/filter-out-blocklisted-events.util.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/filter-out-blocklisted-events.util.ts similarity index 100% rename from packages/twenty-server/src/modules/calendar/utils/filter-out-blocklisted-events.util.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/filter-out-blocklisted-events.util.ts diff --git a/packages/twenty-server/src/modules/calendar/utils/format-google-calendar-event.util.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/format-google-calendar-event.util.ts similarity index 94% rename from packages/twenty-server/src/modules/calendar/utils/format-google-calendar-event.util.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/format-google-calendar-event.util.ts index bb8a4523a3..10f8e2fc14 100644 --- a/packages/twenty-server/src/modules/calendar/utils/format-google-calendar-event.util.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/format-google-calendar-event.util.ts @@ -1,8 +1,8 @@ import { calendar_v3 as calendarV3 } from 'googleapis'; import { v4 } from 'uuid'; -import { CalendarEventParticipantResponseStatus } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; -import { CalendarEventWithParticipants } from 'src/modules/calendar/types/calendar-event'; +import { CalendarEventWithParticipants } from 'src/modules/calendar/common/types/calendar-event'; +import { CalendarEventParticipantResponseStatus } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; export const formatGoogleCalendarEvent = ( event: calendarV3.Schema$Event, diff --git a/packages/twenty-server/src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/get-flattened-values-and-values-string-for-batch-raw-query.util.ts similarity index 100% rename from packages/twenty-server/src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-import-manager/utils/get-flattened-values-and-values-string-for-batch-raw-query.util.ts diff --git a/packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module.ts similarity index 58% rename from packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module.ts index 212a087dbf..dc3cd2a7e2 100644 --- a/packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module.ts @@ -1,11 +1,15 @@ import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; +import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; import { AddPersonIdAndWorkspaceMemberIdModule } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.module'; -import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventParticipantListener } from 'src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant.listener'; +import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; @Module({ @@ -13,9 +17,16 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso WorkspaceDataSourceModule, TwentyORMModule.forFeature([CalendarEventParticipantWorkspaceEntity]), ObjectMetadataRepositoryModule.forFeature([PersonWorkspaceEntity]), + TypeOrmModule.forFeature( + [ObjectMetadataEntity, FieldMetadataEntity], + 'metadata', + ), AddPersonIdAndWorkspaceMemberIdModule, ], - providers: [CalendarEventParticipantService], + providers: [ + CalendarEventParticipantService, + CalendarEventParticipantListener, + ], exports: [CalendarEventParticipantService], }) export class CalendarEventParticipantModule {} diff --git a/packages/twenty-server/src/modules/calendar/listeners/calendar-event-participant.listener.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant.listener.ts similarity index 97% rename from packages/twenty-server/src/modules/calendar/listeners/calendar-event-participant.listener.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant.listener.ts index 852b7919af..b28a730339 100644 --- a/packages/twenty-server/src/modules/calendar/listeners/calendar-event-participant.listener.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant.listener.ts @@ -7,9 +7,9 @@ import { Repository } from 'typeorm'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository'; import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @Injectable() export class CalendarEventParticipantListener { diff --git a/packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts similarity index 95% rename from packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service.ts rename to packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts index 3d46165d02..9fe93bc6f4 100644 --- a/packages/twenty-server/src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts @@ -7,12 +7,12 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos import { PersonRepository } from 'src/modules/person/repositories/person.repository'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; -import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; -import { CalendarEventParticipant } from 'src/modules/calendar/types/calendar-event'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; +import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/calendar-event-import-manager/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; +import { CalendarEventParticipant } from 'src/modules/calendar/common/types/calendar-event'; import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @Injectable() export class CalendarEventParticipantService { diff --git a/packages/twenty-server/src/modules/calendar/calendar.module.ts b/packages/twenty-server/src/modules/calendar/calendar.module.ts index d6a63b5a20..f7fafef3ef 100644 --- a/packages/twenty-server/src/modules/calendar/calendar.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar.module.ts @@ -1,27 +1,18 @@ import { Module } from '@nestjs/common'; -import { TypeOrmModule } from '@nestjs/typeorm'; -import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; -import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; -import { CalendarBlocklistListener } from 'src/modules/calendar/listeners/calendar-blocklist.listener'; -import { CalendarChannelListener } from 'src/modules/calendar/listeners/calendar-channel.listener'; -import { CalendarEventParticipantListener } from 'src/modules/calendar/listeners/calendar-event-participant.listener'; -import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; +import { CalendarBlocklistManagerModule } from 'src/modules/calendar/blocklist-manager/calendar-blocklist-manager.module'; +import { CalendarEventCleanerModule } from 'src/modules/calendar/calendar-event-cleaner/calendar-event-cleaner.module'; +import { CalendarEventImportManagerModule } from 'src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module'; +import { CalendarEventParticipantModule } from 'src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module'; @Module({ imports: [ - WorkspaceDataSourceModule, - ObjectMetadataRepositoryModule.forFeature([ - TimelineActivityWorkspaceEntity, - ]), - TypeOrmModule.forFeature([ObjectMetadataEntity], 'metadata'), - ], - providers: [ - CalendarChannelListener, - CalendarBlocklistListener, - CalendarEventParticipantListener, + CalendarBlocklistManagerModule, + CalendarEventCleanerModule, + CalendarEventImportManagerModule, + CalendarEventParticipantModule, ], + providers: [], exports: [], }) export class CalendarModule {} diff --git a/packages/twenty-server/src/modules/calendar/commands/calendar-commands.module.ts b/packages/twenty-server/src/modules/calendar/commands/calendar-commands.module.ts deleted file mode 100644 index 0c0acf8128..0000000000 --- a/packages/twenty-server/src/modules/calendar/commands/calendar-commands.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { GoogleCalendarSyncCommand } from 'src/modules/calendar/commands/google-calendar-sync.command'; -import { WorkspaceGoogleCalendarSyncModule } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module'; - -@Module({ - imports: [WorkspaceGoogleCalendarSyncModule], - providers: [GoogleCalendarSyncCommand], -}) -export class CalendarCommandsModule {} diff --git a/packages/twenty-server/src/modules/calendar/commands/google-calendar-sync.command.ts b/packages/twenty-server/src/modules/calendar/commands/google-calendar-sync.command.ts deleted file mode 100644 index f605ad7425..0000000000 --- a/packages/twenty-server/src/modules/calendar/commands/google-calendar-sync.command.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Command, CommandRunner, Option } from 'nest-commander'; - -import { WorkspaceGoogleCalendarSyncService } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service'; - -interface GoogleCalendarSyncOptions { - workspaceId: string; -} - -@Command({ - name: 'workspace:google-calendar-sync', - description: - 'Start google calendar sync for all workspaceMembers in a workspace.', -}) -export class GoogleCalendarSyncCommand extends CommandRunner { - constructor( - private readonly workspaceGoogleCalendarSyncService: WorkspaceGoogleCalendarSyncService, - ) { - super(); - } - - @Option({ - flags: '-w, --workspace-id [workspace_id]', - description: 'workspace id', - required: true, - }) - parseWorkspaceId(value: string): string { - return value; - } - - async run( - _passedParam: string[], - options: GoogleCalendarSyncOptions, - ): Promise { - await this.workspaceGoogleCalendarSyncService.startWorkspaceGoogleCalendarSync( - options.workspaceId, - ); - - return; - } -} diff --git a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts similarity index 92% rename from packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts rename to packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts index b46693fb14..8660401f12 100644 --- a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts +++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook.ts @@ -3,11 +3,11 @@ import { BadRequestException, NotFoundException, Scope } from '@nestjs/common'; import { FindManyResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface'; import { WorkspaceQueryHookInstance } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/interfaces/workspace-query-hook.interface'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CanAccessCalendarEventService } from 'src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator'; +import { CanAccessCalendarEventService } from 'src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; @WorkspaceQueryHook({ key: `calendarEvent.findMany`, diff --git a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts similarity index 92% rename from packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts rename to packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts index d95c3aaf5e..add123542b 100644 --- a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts +++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook.ts @@ -6,8 +6,8 @@ import { FindOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-b import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; -import { CanAccessCalendarEventService } from 'src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CanAccessCalendarEventService } from 'src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; @WorkspaceQueryHook({ key: `calendarEvent.findOne`, diff --git a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service.ts similarity index 94% rename from packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service.ts rename to packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service.ts index 80528e0400..fcd05354a7 100644 --- a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service.ts +++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service.ts @@ -6,15 +6,15 @@ import { Any } from 'typeorm'; import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { - CalendarChannelWorkspaceEntity, - CalendarChannelVisibility, -} from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { + CalendarChannelWorkspaceEntity, + CalendarChannelVisibility, +} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; @Injectable() export class CanAccessCalendarEventService { diff --git a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-query-hook.module.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-query-hook.module.ts similarity index 75% rename from packages/twenty-server/src/modules/calendar/query-hooks/calendar-query-hook.module.ts rename to packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-query-hook.module.ts index c85bf53c73..e3a16adf89 100644 --- a/packages/twenty-server/src/modules/calendar/query-hooks/calendar-query-hook.module.ts +++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-query-hook.module.ts @@ -3,12 +3,12 @@ import { Module } from '@nestjs/common'; import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarEventFindManyPreQueryHook } from 'src/modules/calendar/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook'; -import { CalendarEventFindOnePreQueryHook } from 'src/modules/calendar/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook'; -import { CanAccessCalendarEventService } from 'src/modules/calendar/query-hooks/calendar-event/services/can-access-calendar-event.service'; import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; +import { CalendarEventFindManyPreQueryHook } from 'src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.pre-query.hook'; +import { CalendarEventFindOnePreQueryHook } from 'src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.pre-query-hook'; +import { CanAccessCalendarEventService } from 'src/modules/calendar/common/query-hooks/calendar-event/services/can-access-calendar-event.service'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; @Module({ imports: [ diff --git a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity.ts b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity.ts similarity index 96% rename from packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity.ts rename to packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity.ts index fdae18bc85..f1475da3b0 100644 --- a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity.ts +++ b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity.ts @@ -3,7 +3,6 @@ import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/i import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; import { CALENDAR_CHANNEL_EVENT_ASSOCIATION_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator'; import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator'; import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator'; @@ -11,8 +10,9 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator'; import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.calendarChannelEventAssociation, diff --git a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel.workspace-entity.ts b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity.ts similarity index 99% rename from packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel.workspace-entity.ts rename to packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity.ts index cbade9375a..88a5498477 100644 --- a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-channel.workspace-entity.ts +++ b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity.ts @@ -8,7 +8,6 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/fi import { CALENDAR_CHANNEL_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator'; import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator'; @@ -17,6 +16,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; export enum CalendarChannelVisibility { METADATA = 'METADATA', diff --git a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity.ts b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity.ts similarity index 98% rename from packages/twenty-server/src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity.ts rename to packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity.ts index 3cf8f25b2e..4d8727a50f 100644 --- a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity.ts +++ b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity.ts @@ -3,7 +3,6 @@ import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/i import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; import { CALENDAR_EVENT_PARTICIPANT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; @@ -15,6 +14,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; export enum CalendarEventParticipantResponseStatus { NEEDS_ACTION = 'NEEDS_ACTION', diff --git a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-event.workspace-entity.ts b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event.workspace-entity.ts similarity index 97% rename from packages/twenty-server/src/modules/calendar/standard-objects/calendar-event.workspace-entity.ts rename to packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event.workspace-entity.ts index d8d9052d27..a4609608a2 100644 --- a/packages/twenty-server/src/modules/calendar/standard-objects/calendar-event.workspace-entity.ts +++ b/packages/twenty-server/src/modules/calendar/common/standard-objects/calendar-event.workspace-entity.ts @@ -5,8 +5,6 @@ import { RelationMetadataType, RelationOnDeleteAction, } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; import { CALENDAR_EVENT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { LinkMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/link.composite-type'; @@ -17,6 +15,8 @@ import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/work import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator'; import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; +import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.calendarEvent, diff --git a/packages/twenty-server/src/modules/calendar/types/calendar-event.ts b/packages/twenty-server/src/modules/calendar/common/types/calendar-event.ts similarity index 85% rename from packages/twenty-server/src/modules/calendar/types/calendar-event.ts rename to packages/twenty-server/src/modules/calendar/common/types/calendar-event.ts index f727691c1d..0e0d3f5be4 100644 --- a/packages/twenty-server/src/modules/calendar/types/calendar-event.ts +++ b/packages/twenty-server/src/modules/calendar/common/types/calendar-event.ts @@ -1,5 +1,5 @@ -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; -import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; +import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity'; export type CalendarEvent = Omit< CalendarEventWorkspaceEntity, diff --git a/packages/twenty-server/src/modules/calendar/crons/commands/calendar-cron-commands.module.ts b/packages/twenty-server/src/modules/calendar/crons/commands/calendar-cron-commands.module.ts deleted file mode 100644 index 30df8fe7da..0000000000 --- a/packages/twenty-server/src/modules/calendar/crons/commands/calendar-cron-commands.module.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { GoogleCalendarSyncCronCommand } from 'src/modules/calendar/crons/commands/google-calendar-sync.cron.command'; - -@Module({ - providers: [GoogleCalendarSyncCronCommand], -}) -export class CalendarCronCommandsModule {} diff --git a/packages/twenty-server/src/modules/calendar/crons/jobs/calendar-cron-job.module.ts b/packages/twenty-server/src/modules/calendar/crons/jobs/calendar-cron-job.module.ts deleted file mode 100644 index 38be6456d4..0000000000 --- a/packages/twenty-server/src/modules/calendar/crons/jobs/calendar-cron-job.module.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Module } from '@nestjs/common'; -import { TypeOrmModule } from '@nestjs/typeorm'; - -import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; -import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity'; -import { GoogleCalendarSyncCronJob } from 'src/modules/calendar/crons/jobs/google-calendar-sync.cron.job'; -import { WorkspaceGoogleCalendarSyncModule } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module'; -import { BillingModule } from 'src/engine/core-modules/billing/billing.module'; - -@Module({ - imports: [ - TypeOrmModule.forFeature([FeatureFlagEntity], 'core'), - TypeOrmModule.forFeature([DataSourceEntity], 'metadata'), - WorkspaceGoogleCalendarSyncModule, - BillingModule, - ], - providers: [GoogleCalendarSyncCronJob], -}) -export class CalendarCronJobModule {} diff --git a/packages/twenty-server/src/modules/calendar/crons/jobs/google-calendar-sync.cron.job.ts b/packages/twenty-server/src/modules/calendar/crons/jobs/google-calendar-sync.cron.job.ts deleted file mode 100644 index 40b56c1b4f..0000000000 --- a/packages/twenty-server/src/modules/calendar/crons/jobs/google-calendar-sync.cron.job.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { InjectRepository } from '@nestjs/typeorm'; -import { Scope } from '@nestjs/common'; - -import { Repository, In } from 'typeorm'; - -import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity'; -import { WorkspaceGoogleCalendarSyncService } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service'; -import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; -import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; -import { BillingService } from 'src/engine/core-modules/billing/billing.service'; - -@Processor({ - queueName: MessageQueue.cronQueue, - scope: Scope.REQUEST, -}) -export class GoogleCalendarSyncCronJob { - constructor( - @InjectRepository(DataSourceEntity, 'metadata') - private readonly dataSourceRepository: Repository, - private readonly workspaceGoogleCalendarSyncService: WorkspaceGoogleCalendarSyncService, - private readonly billingService: BillingService, - ) {} - - @Process(GoogleCalendarSyncCronJob.name) - async handle(): Promise { - const workspaceIds = - await this.billingService.getActiveSubscriptionWorkspaceIds(); - - const dataSources = await this.dataSourceRepository.find({ - where: { - workspaceId: In(workspaceIds), - }, - }); - - const workspaceIdsWithDataSources = new Set( - dataSources.map((dataSource) => dataSource.workspaceId), - ); - - for (const workspaceId of workspaceIdsWithDataSources) { - await this.workspaceGoogleCalendarSyncService.startWorkspaceGoogleCalendarSync( - workspaceId, - ); - } - } -} diff --git a/packages/twenty-server/src/modules/calendar/jobs/calendar-job.module.ts b/packages/twenty-server/src/modules/calendar/jobs/calendar-job.module.ts deleted file mode 100644 index b419764970..0000000000 --- a/packages/twenty-server/src/modules/calendar/jobs/calendar-job.module.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; -import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; -import { BlocklistItemDeleteCalendarEventsJob } from 'src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job'; -import { BlocklistReimportCalendarEventsJob } from 'src/modules/calendar/jobs/blocklist-reimport-calendar-events.job'; -import { CalendarCreateCompanyAndContactAfterSyncJob } from 'src/modules/calendar/jobs/calendar-create-company-and-contact-after-sync.job'; -import { DeleteConnectedAccountAssociatedCalendarDataJob } from 'src/modules/calendar/jobs/delete-connected-account-associated-calendar-data.job'; -import { GoogleCalendarSyncJob } from 'src/modules/calendar/jobs/google-calendar-sync.job'; -import { CalendarEventCleanerModule } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.module'; -import { GoogleCalendarSyncModule } from 'src/modules/calendar/services/google-calendar-sync/google-calendar-sync.module'; -import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.workspace-entity'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; -import { AutoCompaniesAndContactsCreationModule } from 'src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module'; -import { GoogleAPIRefreshAccessTokenModule } from 'src/modules/connected-account/services/google-api-refresh-access-token/google-api-refresh-access-token.module'; -import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; -import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; - -@Module({ - imports: [ - TwentyORMModule.forFeature([ - CalendarChannelWorkspaceEntity, - CalendarChannelEventAssociationWorkspaceEntity, - CalendarEventParticipantWorkspaceEntity, - ]), - ObjectMetadataRepositoryModule.forFeature([ - ConnectedAccountWorkspaceEntity, - BlocklistWorkspaceEntity, - ]), - CalendarEventCleanerModule, - AutoCompaniesAndContactsCreationModule, - GoogleCalendarSyncModule, - GoogleAPIRefreshAccessTokenModule, - GoogleCalendarSyncModule, - ], - providers: [ - BlocklistItemDeleteCalendarEventsJob, - BlocklistReimportCalendarEventsJob, - GoogleCalendarSyncJob, - CalendarCreateCompanyAndContactAfterSyncJob, - DeleteConnectedAccountAssociatedCalendarDataJob, - ], -}) -export class CalendarJobModule {} diff --git a/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module.ts b/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module.ts deleted file mode 100644 index f2c009caf2..0000000000 --- a/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; -import { WorkspaceGoogleCalendarSyncService } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; - -@Module({ - imports: [TwentyORMModule.forFeature([CalendarChannelWorkspaceEntity])], - providers: [WorkspaceGoogleCalendarSyncService], - exports: [WorkspaceGoogleCalendarSyncService], -}) -export class WorkspaceGoogleCalendarSyncModule {} diff --git a/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service.ts b/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service.ts deleted file mode 100644 index 9b2fd6c5af..0000000000 --- a/packages/twenty-server/src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; -import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; -import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; -import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; -import { - GoogleCalendarSyncJobData, - GoogleCalendarSyncJob, -} from 'src/modules/calendar/jobs/google-calendar-sync.job'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; - -@Injectable() -export class WorkspaceGoogleCalendarSyncService { - constructor( - @InjectWorkspaceRepository(CalendarChannelWorkspaceEntity) - private readonly calendarChannelRepository: WorkspaceRepository, - @InjectMessageQueue(MessageQueue.calendarQueue) - private readonly messageQueueService: MessageQueueService, - ) {} - - public async startWorkspaceGoogleCalendarSync( - workspaceId: string, - ): Promise { - const calendarChannels = await this.calendarChannelRepository.find({}); - - for (const calendarChannel of calendarChannels) { - if (!calendarChannel?.isSyncEnabled) { - continue; - } - - await this.messageQueueService.add( - GoogleCalendarSyncJob.name, - { - workspaceId, - connectedAccountId: calendarChannel.connectedAccount.id, - }, - { - retryLimit: 2, - }, - ); - } - } -} diff --git a/packages/twenty-server/src/modules/calendar/utils/google-calendar-search-filter.util.ts b/packages/twenty-server/src/modules/calendar/utils/google-calendar-search-filter.util.ts deleted file mode 100644 index e9dc788d9f..0000000000 --- a/packages/twenty-server/src/modules/calendar/utils/google-calendar-search-filter.util.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const googleCalendarSearchFilterExcludeEmails = ( - emails: string[], -): string | undefined => { - if (emails.length === 0) { - return undefined; - } - - return `-(${emails.join(', ')})`; -}; diff --git a/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module.ts b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module.ts index b46d31df22..3ab85291b1 100644 --- a/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module.ts +++ b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module.ts @@ -8,10 +8,11 @@ import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repos import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; -import { CalendarEventParticipantModule } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module'; import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module'; +import { CalendarEventParticipantModule } from 'src/modules/calendar/calendar-event-participant-manager/calendar-event-participant.module'; import { AutoCompaniesAndContactsCreationMessageChannelListener } from 'src/modules/connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-message-channel.listener'; +import { AutoCompaniesAndContactsCreationCalendarChannelListener } from 'src/modules/connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-calendar-channel.listener'; @Module({ imports: [ @@ -29,6 +30,7 @@ import { AutoCompaniesAndContactsCreationMessageChannelListener } from 'src/modu providers: [ CreateCompanyAndContactService, AutoCompaniesAndContactsCreationMessageChannelListener, + AutoCompaniesAndContactsCreationCalendarChannelListener, ], exports: [CreateCompanyAndContactService], }) diff --git a/packages/twenty-server/src/modules/calendar/listeners/calendar-channel.listener.ts b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts similarity index 90% rename from packages/twenty-server/src/modules/calendar/listeners/calendar-channel.listener.ts rename to packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts index 9e43de7124..85c5467b9c 100644 --- a/packages/twenty-server/src/modules/calendar/listeners/calendar-channel.listener.ts +++ b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts @@ -6,14 +6,14 @@ import { objectRecordChangedProperties } from 'src/engine/integrations/event-emi import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; +import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; import { CalendarCreateCompanyAndContactAfterSyncJobData, CalendarCreateCompanyAndContactAfterSyncJob, -} from 'src/modules/calendar/jobs/calendar-create-company-and-contact-after-sync.job'; -import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; +} from 'src/modules/messaging/message-participants-manager/jobs/calendar-create-company-and-contact-after-sync.job'; @Injectable() -export class CalendarChannelListener { +export class AutoCompaniesAndContactsCreationCalendarChannelListener { constructor( @InjectMessageQueue(MessageQueue.calendarQueue) private readonly messageQueueService: MessageQueueService, diff --git a/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service.ts b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service.ts index 06f690a7e6..bc18008419 100644 --- a/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service.ts +++ b/packages/twenty-server/src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service.ts @@ -15,16 +15,16 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; import { getUniqueContactsAndHandles } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/get-unique-contacts-and-handles.util'; -import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service'; import { filterOutSelfAndContactsFromCompanyOrWorkspace } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/filter-out-contacts-from-company-or-workspace.util'; import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service'; import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource'; import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; +import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service'; import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/connected-account/auto-companies-and-contacts-creation/constants/contacts-creation-batch-size.constant'; import { Contact } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @Injectable() export class CreateCompanyAndContactService { diff --git a/packages/twenty-server/src/modules/connected-account/standard-objects/connected-account.workspace-entity.ts b/packages/twenty-server/src/modules/connected-account/standard-objects/connected-account.workspace-entity.ts index a13c7fb2dd..88304baada 100644 --- a/packages/twenty-server/src/modules/connected-account/standard-objects/connected-account.workspace-entity.ts +++ b/packages/twenty-server/src/modules/connected-account/standard-objects/connected-account.workspace-entity.ts @@ -7,7 +7,6 @@ import { } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; import { CONNECTED_ACCOUNT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity'; import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator'; @@ -20,6 +19,7 @@ import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/stan import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; import { WorkspaceGate } from 'src/engine/twenty-orm/decorators/workspace-gate.decorator'; import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; export enum ConnectedAccountProvider { GOOGLE = 'google', diff --git a/packages/twenty-server/src/modules/messaging/common/services/messaging-message-participant.service.ts b/packages/twenty-server/src/modules/messaging/common/services/messaging-message-participant.service.ts index 6251910613..3d1da461e7 100644 --- a/packages/twenty-server/src/modules/messaging/common/services/messaging-message-participant.service.ts +++ b/packages/twenty-server/src/modules/messaging/common/services/messaging-message-participant.service.ts @@ -7,7 +7,7 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos import { PersonRepository } from 'src/modules/person/repositories/person.repository'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; -import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; +import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/calendar-event-import-manager/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service'; import { MessageParticipantRepository } from 'src/modules/messaging/common/repositories/message-participant.repository'; import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; diff --git a/packages/twenty-server/src/modules/messaging/message-cleaner/listeners/messaging-message-cleaner-connected-account.listener.ts b/packages/twenty-server/src/modules/messaging/message-cleaner/listeners/messaging-message-cleaner-connected-account.listener.ts index c3d0149f71..8880ad5d10 100644 --- a/packages/twenty-server/src/modules/messaging/message-cleaner/listeners/messaging-message-cleaner-connected-account.listener.ts +++ b/packages/twenty-server/src/modules/messaging/message-cleaner/listeners/messaging-message-cleaner-connected-account.listener.ts @@ -4,16 +4,16 @@ import { OnEvent } from '@nestjs/event-emitter'; import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/types/object-record-delete.event'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; -import { - DeleteConnectedAccountAssociatedCalendarDataJobData, - DeleteConnectedAccountAssociatedCalendarDataJob, -} from 'src/modules/calendar/jobs/delete-connected-account-associated-calendar-data.job'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; import { MessagingConnectedAccountDeletionCleanupJob, MessagingConnectedAccountDeletionCleanupJobData, } from 'src/modules/messaging/message-cleaner/jobs/messaging-connected-account-deletion-cleanup.job'; import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; +import { + DeleteConnectedAccountAssociatedCalendarDataJobData, + DeleteConnectedAccountAssociatedCalendarDataJob, +} from 'src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job'; @Injectable() export class MessagingMessageCleanerConnectedAccountListener { diff --git a/packages/twenty-server/src/modules/calendar/jobs/calendar-create-company-and-contact-after-sync.job.ts b/packages/twenty-server/src/modules/messaging/message-participants-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts similarity index 96% rename from packages/twenty-server/src/modules/calendar/jobs/calendar-create-company-and-contact-after-sync.job.ts rename to packages/twenty-server/src/modules/messaging/message-participants-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts index 3ca7266340..9d2e442fc2 100644 --- a/packages/twenty-server/src/modules/calendar/jobs/calendar-create-company-and-contact-after-sync.job.ts +++ b/packages/twenty-server/src/modules/messaging/message-participants-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts @@ -4,12 +4,12 @@ import { IsNull } from 'typeorm'; import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; -import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { CreateCompanyAndContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service'; import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; export type CalendarCreateCompanyAndContactAfterSyncJobData = { workspaceId: string; diff --git a/packages/twenty-server/src/modules/messaging/message-participants-manager/messaging-participants-manager.module.ts b/packages/twenty-server/src/modules/messaging/message-participants-manager/messaging-participants-manager.module.ts index 6d04a306ce..5767093b94 100644 --- a/packages/twenty-server/src/modules/messaging/message-participants-manager/messaging-participants-manager.module.ts +++ b/packages/twenty-server/src/modules/messaging/message-participants-manager/messaging-participants-manager.module.ts @@ -5,9 +5,12 @@ import { AnalyticsModule } from 'src/engine/core-modules/analytics/analytics.mod import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module'; +import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; +import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; import { AutoCompaniesAndContactsCreationModule } from 'src/modules/connected-account/auto-companies-and-contacts-creation/auto-companies-and-contacts-creation.module'; import { MessagingGmailDriverModule } from 'src/modules/messaging/message-import-manager/drivers/gmail/messaging-gmail-driver.module'; +import { CalendarCreateCompanyAndContactAfterSyncJob } from 'src/modules/messaging/message-participants-manager/jobs/calendar-create-company-and-contact-after-sync.job'; import { MessagingCreateCompanyAndContactAfterSyncJob } from 'src/modules/messaging/message-participants-manager/jobs/messaging-create-company-and-contact-after-sync.job'; import { MessageParticipantListener } from 'src/modules/messaging/message-participants-manager/listeners/message-participant.listener'; import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; @@ -23,9 +26,11 @@ import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-o TimelineActivityWorkspaceEntity, ]), TypeOrmModule.forFeature([ObjectMetadataEntity], 'metadata'), + TwentyORMModule.forFeature([CalendarChannelWorkspaceEntity]), ], providers: [ MessagingCreateCompanyAndContactAfterSyncJob, + CalendarCreateCompanyAndContactAfterSyncJob, MessageParticipantListener, ], }) diff --git a/packages/twenty-server/src/modules/person/repositories/person.repository.ts b/packages/twenty-server/src/modules/person/repositories/person.repository.ts index df6af48a9b..adb40f1cbd 100644 --- a/packages/twenty-server/src/modules/person/repositories/person.repository.ts +++ b/packages/twenty-server/src/modules/person/repositories/person.repository.ts @@ -4,7 +4,7 @@ import { EntityManager } from 'typeorm'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; -import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; +import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/calendar-event-import-manager/utils/get-flattened-values-and-values-string-for-batch-raw-query.util'; @Injectable() export class PersonRepository { diff --git a/packages/twenty-server/src/modules/person/standard-objects/person.workspace-entity.ts b/packages/twenty-server/src/modules/person/standard-objects/person.workspace-entity.ts index 537a8300f8..0d1704aed6 100644 --- a/packages/twenty-server/src/modules/person/standard-objects/person.workspace-entity.ts +++ b/packages/twenty-server/src/modules/person/standard-objects/person.workspace-entity.ts @@ -11,7 +11,6 @@ import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspac import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; import { ActivityTargetWorkspaceEntity } from 'src/modules/activity/standard-objects/activity-target.workspace-entity'; import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity'; import { FavoriteWorkspaceEntity } from 'src/modules/favorite/standard-objects/favorite.workspace-entity'; import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity'; @@ -24,6 +23,7 @@ import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.person, diff --git a/packages/twenty-server/src/modules/workspace-member/standard-objects/workspace-member.workspace-entity.ts b/packages/twenty-server/src/modules/workspace-member/standard-objects/workspace-member.workspace-entity.ts index 17378a598f..909c2ad938 100644 --- a/packages/twenty-server/src/modules/workspace-member/standard-objects/workspace-member.workspace-entity.ts +++ b/packages/twenty-server/src/modules/workspace-member/standard-objects/workspace-member.workspace-entity.ts @@ -11,7 +11,6 @@ import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/activity.workspace-entity'; import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity'; import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity'; -import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity'; import { CommentWorkspaceEntity } from 'src/modules/activity/standard-objects/comment.workspace-entity'; import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity'; import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; @@ -26,6 +25,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; +import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.workspaceMember,