[backend] rename repository services and replace repository modules by dynamicModule (#4536)
* rename database services to repository * refactor more repositories * more refactoring * followup * remove unused imports * fix * fix * Fix calendar listener being called when flag is off * remove folders
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { DataSourceModule } from 'src/engine-metadata/data-source/data-source.module';
|
||||
import { CalendarEventModule } from 'src/modules/calendar/repositories/calendar-event/calendar-event.module';
|
||||
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
|
||||
import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service';
|
||||
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
|
||||
|
||||
@Module({
|
||||
imports: [DataSourceModule, TypeORMModule, CalendarEventModule],
|
||||
imports: [
|
||||
ObjectMetadataRepositoryModule.forFeature([CalendarEventObjectMetadata]),
|
||||
],
|
||||
providers: [CalendarEventCleanerService],
|
||||
exports: [CalendarEventCleanerService],
|
||||
})
|
||||
|
||||
@ -1,20 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { CalendarEventService } from 'src/modules/calendar/repositories/calendar-event/calendar-event.service';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { CalendarEventRepository } from 'src/modules/calendar/repositories/calendar-event.repository';
|
||||
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
|
||||
import { deleteUsingPagination } from 'src/modules/messaging/services/thread-cleaner/utils/delete-using-pagination.util';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventCleanerService {
|
||||
constructor(private readonly calendarEventService: CalendarEventService) {}
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(CalendarEventObjectMetadata)
|
||||
private readonly calendarEventRepository: CalendarEventRepository,
|
||||
) {}
|
||||
|
||||
public async cleanWorkspaceCalendarEvents(workspaceId: string) {
|
||||
await deleteUsingPagination(
|
||||
workspaceId,
|
||||
500,
|
||||
this.calendarEventService.getNonAssociatedCalendarEventIdsPaginated.bind(
|
||||
this.calendarEventService,
|
||||
this.calendarEventRepository.getNonAssociatedCalendarEventIdsPaginated.bind(
|
||||
this.calendarEventRepository,
|
||||
),
|
||||
this.calendarEventRepository.deleteByIds.bind(
|
||||
this.calendarEventRepository,
|
||||
),
|
||||
this.calendarEventService.deleteByIds.bind(this.calendarEventService),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { FeatureFlagEntity } from 'src/engine/modules/feature-flag/feature-flag.entity';
|
||||
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
|
||||
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
|
||||
import { GoogleCalendarFullSyncService } from 'src/modules/calendar/services/google-calendar-full-sync.service';
|
||||
import { CalendarProvidersModule } from 'src/modules/calendar/services/providers/calendar-providers.module';
|
||||
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
|
||||
import { CalendarChannelObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel.object-metadata';
|
||||
import { CalendarEventAttendeeObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-attendee.object-metadata';
|
||||
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
|
||||
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
|
||||
import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/standard-objects/connected-account.object-metadata';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CalendarProvidersModule,
|
||||
ObjectMetadataRepositoryModule.forFeature([
|
||||
ConnectedAccountObjectMetadata,
|
||||
CalendarEventObjectMetadata,
|
||||
CalendarChannelObjectMetadata,
|
||||
CalendarChannelEventAssociationObjectMetadata,
|
||||
CalendarEventAttendeeObjectMetadata,
|
||||
BlocklistObjectMetadata,
|
||||
PersonObjectMetadata,
|
||||
WorkspaceMemberObjectMetadata,
|
||||
]),
|
||||
TypeOrmModule.forFeature([FeatureFlagEntity], 'core'),
|
||||
WorkspaceDataSourceModule,
|
||||
],
|
||||
providers: [GoogleCalendarFullSyncService],
|
||||
exports: [GoogleCalendarFullSyncService],
|
||||
})
|
||||
export class GoogleCalendarFullSyncModule {}
|
||||
@ -3,23 +3,30 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { ConnectedAccountService } from 'src/modules/connected-account/repositories/connected-account/connected-account.service';
|
||||
import { BlocklistService } from 'src/modules/connected-account/repositories/blocklist/blocklist.service';
|
||||
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
|
||||
import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository';
|
||||
import {
|
||||
FeatureFlagEntity,
|
||||
FeatureFlagKeys,
|
||||
} from 'src/engine/modules/feature-flag/feature-flag.entity';
|
||||
import { GoogleCalendarClientProvider } from 'src/modules/calendar/services/providers/google-calendar/google-calendar.provider';
|
||||
import { googleCalendarSearchFilterExcludeEmails } from 'src/modules/calendar/utils/google-calendar-search-filter.util';
|
||||
import { CalendarChannelEventAssociationService } from 'src/modules/calendar/repositories/calendar-channel-event-association/calendar-channel-event-association.service';
|
||||
import { CalendarChannelService } from 'src/modules/calendar/repositories/calendar-channel/calendar-channel.service';
|
||||
import { CalendarChannelEventAssociationRepository } from 'src/modules/calendar/repositories/calendar-channel-event-association.repository';
|
||||
import { CalendarChannelRepository } from 'src/modules/calendar/repositories/calendar-channel.repository';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { CalendarEventService } from 'src/modules/calendar/repositories/calendar-event/calendar-event.service';
|
||||
import { CalendarEventRepository } from 'src/modules/calendar/repositories/calendar-event.repository';
|
||||
import { formatGoogleCalendarEvent } from 'src/modules/calendar/utils/format-google-calendar-event.util';
|
||||
import { GoogleCalendarFullSyncJobData } from 'src/modules/calendar/jobs/google-calendar-full-sync.job';
|
||||
import { CalendarEventAttendeeService } from 'src/modules/calendar/repositories/calendar-event-attendee/calendar-event-attendee.service';
|
||||
import { CalendarEventAttendeeRepository } from 'src/modules/calendar/repositories/calendar-event-attendee.repository';
|
||||
import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/standard-objects/connected-account.object-metadata';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
|
||||
import { CalendarChannelObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel.object-metadata';
|
||||
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
|
||||
import { CalendarEventAttendeeObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-attendee.object-metadata';
|
||||
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleCalendarFullSyncService {
|
||||
@ -29,12 +36,20 @@ export class GoogleCalendarFullSyncService {
|
||||
private readonly googleCalendarClientProvider: GoogleCalendarClientProvider,
|
||||
@Inject(MessageQueue.calendarQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
private readonly connectedAccountService: ConnectedAccountService,
|
||||
private readonly calendarEventService: CalendarEventService,
|
||||
private readonly calendarChannelService: CalendarChannelService,
|
||||
private readonly calendarChannelEventAssociationService: CalendarChannelEventAssociationService,
|
||||
private readonly calendarEventAttendeesService: CalendarEventAttendeeService,
|
||||
private readonly blocklistService: BlocklistService,
|
||||
@InjectObjectMetadataRepository(ConnectedAccountObjectMetadata)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
@InjectObjectMetadataRepository(CalendarEventObjectMetadata)
|
||||
private readonly calendarEventRepository: CalendarEventRepository,
|
||||
@InjectObjectMetadataRepository(CalendarChannelObjectMetadata)
|
||||
private readonly calendarChannelRepository: CalendarChannelRepository,
|
||||
@InjectObjectMetadataRepository(
|
||||
CalendarChannelEventAssociationObjectMetadata,
|
||||
)
|
||||
private readonly calendarChannelEventAssociationRepository: CalendarChannelEventAssociationRepository,
|
||||
@InjectObjectMetadataRepository(CalendarEventAttendeeObjectMetadata)
|
||||
private readonly calendarEventAttendeesRepository: CalendarEventAttendeeRepository,
|
||||
@InjectObjectMetadataRepository(BlocklistObjectMetadata)
|
||||
private readonly blocklistRepository: BlocklistRepository,
|
||||
@InjectRepository(FeatureFlagEntity, 'core')
|
||||
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
@ -45,7 +60,7 @@ export class GoogleCalendarFullSyncService {
|
||||
connectedAccountId: string,
|
||||
pageToken?: string,
|
||||
): Promise<void> {
|
||||
const connectedAccount = await this.connectedAccountService.getById(
|
||||
const connectedAccount = await this.connectedAccountRepository.getById(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
);
|
||||
@ -64,7 +79,7 @@ export class GoogleCalendarFullSyncService {
|
||||
}
|
||||
|
||||
const calendarChannel =
|
||||
await this.calendarChannelService.getFirstByConnectedAccountIdOrFail(
|
||||
await this.calendarChannelRepository.getFirstByConnectedAccountIdOrFail(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
);
|
||||
@ -87,7 +102,7 @@ export class GoogleCalendarFullSyncService {
|
||||
isBlocklistEnabledFeatureFlag && isBlocklistEnabledFeatureFlag.value;
|
||||
|
||||
const blocklist = isBlocklistEnabled
|
||||
? await this.blocklistService.getByWorkspaceMemberId(
|
||||
? await this.blocklistRepository.getByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
)
|
||||
@ -130,7 +145,7 @@ export class GoogleCalendarFullSyncService {
|
||||
startTime = Date.now();
|
||||
|
||||
const existingCalendarChannelEventAssociations =
|
||||
await this.calendarChannelEventAssociationService.getByEventExternalIdsAndCalendarChannelId(
|
||||
await this.calendarChannelEventAssociationRepository.getByEventExternalIdsAndCalendarChannelId(
|
||||
eventExternalIds,
|
||||
calendarChannelId,
|
||||
workspaceId,
|
||||
@ -180,7 +195,7 @@ export class GoogleCalendarFullSyncService {
|
||||
);
|
||||
|
||||
const iCalUIDCalendarEventIdMap =
|
||||
await this.calendarEventService.getICalUIDCalendarEventIdMap(
|
||||
await this.calendarEventRepository.getICalUIDCalendarEventIdMap(
|
||||
eventsToUpdate.map((event) => event.iCalUID),
|
||||
workspaceId,
|
||||
);
|
||||
@ -192,31 +207,31 @@ export class GoogleCalendarFullSyncService {
|
||||
);
|
||||
|
||||
dataSourceMetadata?.transaction(async (transactionManager) => {
|
||||
this.calendarEventService.saveCalendarEvents(
|
||||
this.calendarEventRepository.saveCalendarEvents(
|
||||
eventsToSave,
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
this.calendarEventService.updateCalendarEvents(
|
||||
this.calendarEventRepository.updateCalendarEvents(
|
||||
eventsToUpdate,
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
this.calendarChannelEventAssociationService.saveCalendarChannelEventAssociations(
|
||||
this.calendarChannelEventAssociationRepository.saveCalendarChannelEventAssociations(
|
||||
calendarChannelEventAssociationsToSave,
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
this.calendarEventAttendeesService.saveCalendarEventAttendees(
|
||||
this.calendarEventAttendeesRepository.saveCalendarEventAttendees(
|
||||
attendeesToSave,
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
this.calendarEventAttendeesService.updateCalendarEventAttendees(
|
||||
this.calendarEventAttendeesRepository.updateCalendarEventAttendees(
|
||||
attendeesToUpdate,
|
||||
iCalUIDCalendarEventIdMap,
|
||||
workspaceId,
|
||||
|
||||
Reference in New Issue
Block a user