Deprecate inject workspace repo (#6353)
This commit is contained in:
@ -6,13 +6,10 @@ import { Process } from 'src/engine/integrations/message-queue/decorators/proces
|
||||
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 { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { BlocklistRepository } from 'src/modules/blocklist/repositories/blocklist.repository';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
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;
|
||||
@ -29,10 +26,7 @@ export class BlocklistItemDeleteCalendarEventsJob {
|
||||
);
|
||||
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(CalendarChannelEventAssociationWorkspaceEntity)
|
||||
private readonly calendarChannelEventAssociationRepository: WorkspaceRepository<CalendarChannelEventAssociationWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectObjectMetadataRepository(BlocklistWorkspaceEntity)
|
||||
private readonly blocklistRepository: BlocklistRepository,
|
||||
private readonly calendarEventCleanerService: CalendarEventCleanerService,
|
||||
@ -67,7 +61,10 @@ export class BlocklistItemDeleteCalendarEventsJob {
|
||||
);
|
||||
}
|
||||
|
||||
const calendarChannels = await this.calendarChannelRepository.find({
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository('calendarChannel');
|
||||
|
||||
const calendarChannels = await calendarChannelRepository.find({
|
||||
where: {
|
||||
connectedAccount: {
|
||||
accountOwnerId: workspaceMemberId,
|
||||
@ -79,7 +76,12 @@ export class BlocklistItemDeleteCalendarEventsJob {
|
||||
|
||||
const isHandleDomain = handle.startsWith('@');
|
||||
|
||||
await this.calendarChannelEventAssociationRepository.delete({
|
||||
const calendarChannelEventAssociationRepository =
|
||||
await this.twentyORMManager.getRepository(
|
||||
'calendarChannelEventAssociation',
|
||||
);
|
||||
|
||||
await calendarChannelEventAssociationRepository.delete({
|
||||
calendarEvent: {
|
||||
calendarEventParticipants: {
|
||||
handle: isHandleDomain ? ILike(`%${handle}`) : handle,
|
||||
|
||||
@ -2,18 +2,17 @@ import { Scope } from '@nestjs/common';
|
||||
|
||||
import { Any } from 'typeorm';
|
||||
|
||||
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 { 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 { 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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import {
|
||||
CalendarChannelSyncStage,
|
||||
CalendarChannelWorkspaceEntity,
|
||||
} from 'src/modules/calendar/common/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';
|
||||
|
||||
export type BlocklistReimportCalendarEventsJobData = {
|
||||
workspaceId: string;
|
||||
@ -26,10 +25,9 @@ export type BlocklistReimportCalendarEventsJobData = {
|
||||
})
|
||||
export class BlocklistReimportCalendarEventsJob {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
) {}
|
||||
|
||||
@Process(BlocklistReimportCalendarEventsJob.name)
|
||||
@ -46,7 +44,11 @@ export class BlocklistReimportCalendarEventsJob {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.calendarChannelRepository.update(
|
||||
const calendarChannelRepository = await this.twentyORMManager.getRepository(
|
||||
CalendarChannelWorkspaceEntity,
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(
|
||||
{
|
||||
connectedAccountId: Any(
|
||||
connectedAccounts.map((connectedAccount) => connectedAccount.id),
|
||||
|
||||
@ -2,38 +2,35 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
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 {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarEventWorkspaceEntity)
|
||||
private readonly calendarEventRepository: WorkspaceRepository<CalendarEventWorkspaceEntity>,
|
||||
) {}
|
||||
constructor(private readonly twentyORMManager: TwentyORMManager) {}
|
||||
|
||||
public async cleanWorkspaceCalendarEvents(workspaceId: string) {
|
||||
const calendarEventRepository =
|
||||
await this.twentyORMManager.getRepository('calendarEvent');
|
||||
|
||||
await deleteUsingPagination(
|
||||
workspaceId,
|
||||
500,
|
||||
async (limit, offset) => {
|
||||
const nonAssociatedCalendarEvents =
|
||||
await this.calendarEventRepository.find({
|
||||
where: {
|
||||
calendarChannelEventAssociations: {
|
||||
id: IsNull(),
|
||||
},
|
||||
const nonAssociatedCalendarEvents = await calendarEventRepository.find({
|
||||
where: {
|
||||
calendarChannelEventAssociations: {
|
||||
id: IsNull(),
|
||||
},
|
||||
take: limit,
|
||||
skip: offset,
|
||||
});
|
||||
},
|
||||
take: limit,
|
||||
skip: offset,
|
||||
});
|
||||
|
||||
return nonAssociatedCalendarEvents.map(({ id }) => id);
|
||||
},
|
||||
async (ids) => {
|
||||
await this.calendarEventRepository.delete({ id: Any(ids) });
|
||||
await calendarEventRepository.delete({ id: Any(ids) });
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,19 +1,18 @@
|
||||
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 { 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';
|
||||
import { isThrottled } from 'src/modules/connected-account/utils/is-throttled';
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CalendarEventsImportService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service';
|
||||
import {
|
||||
CalendarChannelSyncStage,
|
||||
CalendarChannelWorkspaceEntity,
|
||||
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-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 { isThrottled } from 'src/modules/connected-account/utils/is-throttled';
|
||||
|
||||
export type CalendarEventsImportJobData = {
|
||||
calendarChannelId: string;
|
||||
@ -26,18 +25,22 @@ export type CalendarEventsImportJobData = {
|
||||
})
|
||||
export class CalendarEventListFetchJob {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly calendarEventsImportService: CalendarEventsImportService,
|
||||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
) {}
|
||||
|
||||
@Process(CalendarEventListFetchJob.name)
|
||||
async handle(data: CalendarEventsImportJobData): Promise<void> {
|
||||
const { workspaceId, calendarChannelId } = data;
|
||||
|
||||
const calendarChannel = await this.calendarChannelRepository.findOne({
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
const calendarChannel = await calendarChannelRepository.findOne({
|
||||
where: {
|
||||
id: calendarChannelId,
|
||||
isSyncEnabled: true,
|
||||
@ -65,7 +68,7 @@ export class CalendarEventListFetchJob {
|
||||
|
||||
switch (calendarChannel.syncStage) {
|
||||
case CalendarChannelSyncStage.FULL_CALENDAR_EVENT_LIST_FETCH_PENDING:
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncCursor: '',
|
||||
syncStageStartedAt: null,
|
||||
});
|
||||
|
||||
@ -3,8 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
|
||||
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
|
||||
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import {
|
||||
CalendarChannelSyncStage,
|
||||
CalendarChannelSyncStatus,
|
||||
@ -14,14 +13,18 @@ import {
|
||||
@Injectable()
|
||||
export class CalendarChannelSyncStatusService {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectCacheStorage(CacheStorageNamespace.Calendar)
|
||||
private readonly cacheStorage: CacheStorageService,
|
||||
) {}
|
||||
|
||||
public async scheduleFullCalendarEventListFetch(calendarChannelId: string) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage:
|
||||
CalendarChannelSyncStage.FULL_CALENDAR_EVENT_LIST_FETCH_PENDING,
|
||||
});
|
||||
@ -30,14 +33,24 @@ export class CalendarChannelSyncStatusService {
|
||||
public async schedulePartialCalendarEventListFetch(
|
||||
calendarChannelId: string,
|
||||
) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage:
|
||||
CalendarChannelSyncStage.PARTIAL_CALENDAR_EVENT_LIST_FETCH_PENDING,
|
||||
});
|
||||
}
|
||||
|
||||
public async markAsCalendarEventListFetchOngoing(calendarChannelId: string) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage: CalendarChannelSyncStage.CALENDAR_EVENT_LIST_FETCH_ONGOING,
|
||||
syncStatus: CalendarChannelSyncStatus.ONGOING,
|
||||
syncStageStartedAt: new Date().toISOString(),
|
||||
@ -52,7 +65,12 @@ export class CalendarChannelSyncStatusService {
|
||||
`calendar-events-to-import:${workspaceId}:google-calendar:${calendarChannelId}`,
|
||||
);
|
||||
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncCursor: '',
|
||||
syncStageStartedAt: null,
|
||||
throttleFailureCount: 0,
|
||||
@ -62,13 +80,23 @@ export class CalendarChannelSyncStatusService {
|
||||
}
|
||||
|
||||
public async scheduleCalendarEventsImport(calendarChannelId: string) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage: CalendarChannelSyncStage.CALENDAR_EVENTS_IMPORT_PENDING,
|
||||
});
|
||||
}
|
||||
|
||||
public async markAsCalendarEventsImportOngoing(calendarChannelId: string) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage: CalendarChannelSyncStage.CALENDAR_EVENTS_IMPORT_ONGOING,
|
||||
syncStatus: CalendarChannelSyncStatus.ONGOING,
|
||||
});
|
||||
@ -77,7 +105,12 @@ export class CalendarChannelSyncStatusService {
|
||||
public async markAsCompletedAndSchedulePartialMessageListFetch(
|
||||
calendarChannelId: string,
|
||||
) {
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStage:
|
||||
CalendarChannelSyncStage.PARTIAL_CALENDAR_EVENT_LIST_FETCH_PENDING,
|
||||
syncStatus: CalendarChannelSyncStatus.ACTIVE,
|
||||
@ -92,11 +125,16 @@ export class CalendarChannelSyncStatusService {
|
||||
calendarChannelId: string,
|
||||
workspaceId: string,
|
||||
) {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await this.cacheStorage.del(
|
||||
`calendar-events-to-import:${workspaceId}:google-calendar:${calendarChannelId}`,
|
||||
);
|
||||
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStatus: CalendarChannelSyncStatus.FAILED_UNKNOWN,
|
||||
syncStage: CalendarChannelSyncStage.FAILED,
|
||||
});
|
||||
@ -106,11 +144,16 @@ export class CalendarChannelSyncStatusService {
|
||||
calendarChannelId: string,
|
||||
workspaceId: string,
|
||||
) {
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await this.cacheStorage.del(
|
||||
`calendar-events-to-import:${workspaceId}:google-calendar:${calendarChannelId}`,
|
||||
);
|
||||
|
||||
await this.calendarChannelRepository.update(calendarChannelId, {
|
||||
await calendarChannelRepository.update(calendarChannelId, {
|
||||
syncStatus: CalendarChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
|
||||
syncStage: CalendarChannelSyncStage.FAILED,
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CALENDAR_THROTTLE_MAX_ATTEMPTS } from 'src/modules/calendar/calendar-event-import-manager/constants/calendar-throttle-max-attempts';
|
||||
import { CalendarChannelSyncStatusService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-channel-sync-status.service';
|
||||
import { CalendarEventError } from 'src/modules/calendar/calendar-event-import-manager/types/calendar-event-error.type';
|
||||
@ -16,9 +15,8 @@ export enum CalendarEventImportSyncStep {
|
||||
@Injectable()
|
||||
export class CalendarEventImportErrorHandlerService {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly calendarChannelSyncStatusService: CalendarChannelSyncStatusService,
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
) {}
|
||||
|
||||
public async handleError(
|
||||
@ -68,7 +66,12 @@ export class CalendarEventImportErrorHandlerService {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.calendarChannelRepository.increment(
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
await calendarChannelRepository.increment(
|
||||
{
|
||||
id: calendarChannel.id,
|
||||
},
|
||||
|
||||
@ -3,8 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { BlocklistRepository } from 'src/modules/blocklist/repositories/blocklist.repository';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service';
|
||||
@ -29,10 +28,7 @@ import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/s
|
||||
@Injectable()
|
||||
export class CalendarEventsImportService {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(CalendarChannelEventAssociationWorkspaceEntity)
|
||||
private readonly calendarChannelEventAssociationRepository: WorkspaceRepository<CalendarChannelEventAssociationWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectObjectMetadataRepository(BlocklistWorkspaceEntity)
|
||||
private readonly blocklistRepository: BlocklistRepository,
|
||||
private readonly calendarEventCleanerService: CalendarEventCleanerService,
|
||||
@ -79,8 +75,13 @@ export class CalendarEventsImportService {
|
||||
return;
|
||||
}
|
||||
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
if (!calendarEvents || calendarEvents?.length === 0) {
|
||||
await this.calendarChannelRepository.update(
|
||||
await calendarChannelRepository.update(
|
||||
{
|
||||
id: calendarChannel.id,
|
||||
},
|
||||
@ -117,7 +118,12 @@ export class CalendarEventsImportService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.calendarChannelEventAssociationRepository.delete({
|
||||
const calendarChannelEventAssociationRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
||||
'calendarChannelEventAssociation',
|
||||
);
|
||||
|
||||
await calendarChannelEventAssociationRepository.delete({
|
||||
eventExternalId: Any(cancelledEventExternalIds),
|
||||
calendarChannel: {
|
||||
id: calendarChannel.id,
|
||||
@ -128,7 +134,7 @@ export class CalendarEventsImportService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.calendarChannelRepository.update(
|
||||
await calendarChannelRepository.update(
|
||||
{
|
||||
id: calendarChannel.id,
|
||||
},
|
||||
|
||||
@ -8,8 +8,7 @@ import { MessageQueue } from 'src/engine/integrations/message-queue/message-queu
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource';
|
||||
import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { injectIdsInCalendarEvents } from 'src/modules/calendar/calendar-event-import-manager/utils/inject-ids-in-calendar-events.util';
|
||||
import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service';
|
||||
import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity';
|
||||
@ -26,10 +25,7 @@ import {
|
||||
@Injectable()
|
||||
export class CalendarSaveEventsService {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarEventWorkspaceEntity)
|
||||
private readonly calendarEventRepository: WorkspaceRepository<CalendarEventWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(CalendarChannelEventAssociationWorkspaceEntity)
|
||||
private readonly calendarChannelEventAssociationRepository: WorkspaceRepository<CalendarChannelEventAssociationWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectWorkspaceDatasource()
|
||||
private readonly workspaceDataSource: WorkspaceDataSource,
|
||||
private readonly calendarEventParticipantService: CalendarEventParticipantService,
|
||||
@ -44,7 +40,12 @@ export class CalendarSaveEventsService {
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
const existingCalendarEvents = await this.calendarEventRepository.find({
|
||||
const calendarEventRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarEventWorkspaceEntity>(
|
||||
'calendarEvent',
|
||||
);
|
||||
|
||||
const existingCalendarEvents = await calendarEventRepository.find({
|
||||
where: {
|
||||
iCalUID: Any(filteredEvents.map((event) => event.iCalUID as string)),
|
||||
},
|
||||
@ -77,8 +78,13 @@ export class CalendarSaveEventsService {
|
||||
existingEventsICalUIDs.includes(calendarEvent.iCalUID),
|
||||
);
|
||||
|
||||
const calendarChannelEventAssociationRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
||||
'calendarChannelEventAssociation',
|
||||
);
|
||||
|
||||
const existingCalendarChannelEventAssociations =
|
||||
await this.calendarChannelEventAssociationRepository.find({
|
||||
await calendarChannelEventAssociationRepository.find({
|
||||
where: {
|
||||
eventExternalId: Any(
|
||||
calendarEventsWithIds.map((calendarEvent) => calendarEvent.id),
|
||||
@ -114,19 +120,15 @@ export class CalendarSaveEventsService {
|
||||
[];
|
||||
|
||||
await this.workspaceDataSource?.transaction(async (transactionManager) => {
|
||||
await this.calendarEventRepository.save(
|
||||
eventsToSave,
|
||||
{},
|
||||
transactionManager,
|
||||
);
|
||||
await calendarEventRepository.save(eventsToSave, {}, transactionManager);
|
||||
|
||||
await this.calendarEventRepository.save(
|
||||
await calendarEventRepository.save(
|
||||
eventsToUpdate,
|
||||
{},
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
await this.calendarChannelEventAssociationRepository.save(
|
||||
await calendarChannelEventAssociationRepository.save(
|
||||
calendarChannelEventAssociationsToSave,
|
||||
{},
|
||||
transactionManager,
|
||||
|
||||
@ -5,8 +5,7 @@ import { IsNull } from 'typeorm';
|
||||
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 { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
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 { CreateCompanyAndContactService } from 'src/modules/contact-creation-manager/services/create-company-and-contact.service';
|
||||
@ -25,11 +24,8 @@ export class CalendarCreateCompanyAndContactAfterSyncJob {
|
||||
CalendarCreateCompanyAndContactAfterSyncJob.name,
|
||||
);
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly createCompanyAndContactService: CreateCompanyAndContactService,
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(CalendarEventParticipantWorkspaceEntity)
|
||||
private readonly calendarEventParticipantRepository: WorkspaceRepository<CalendarEventParticipantWorkspaceEntity>,
|
||||
) {}
|
||||
|
||||
@Process(CalendarCreateCompanyAndContactAfterSyncJob.name)
|
||||
@ -41,7 +37,12 @@ export class CalendarCreateCompanyAndContactAfterSyncJob {
|
||||
);
|
||||
const { workspaceId, calendarChannelId } = data;
|
||||
|
||||
const calendarChannel = await this.calendarChannelRepository.findOne({
|
||||
const calendarChannelRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
const calendarChannel = await calendarChannelRepository.findOne({
|
||||
where: {
|
||||
id: calendarChannelId,
|
||||
},
|
||||
@ -67,8 +68,13 @@ export class CalendarCreateCompanyAndContactAfterSyncJob {
|
||||
);
|
||||
}
|
||||
|
||||
const calendarEventParticipantRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarEventParticipantWorkspaceEntity>(
|
||||
'calendarEventParticipant',
|
||||
);
|
||||
|
||||
const calendarEventParticipantsWithoutPersonIdAndWorkspaceMemberId =
|
||||
await this.calendarEventParticipantRepository.find({
|
||||
await calendarEventParticipantRepository.find({
|
||||
where: {
|
||||
calendarEvent: {
|
||||
calendarChannelEventAssociations: {
|
||||
|
||||
@ -5,16 +5,14 @@ import { isDefined } from 'class-validator';
|
||||
import differenceWith from 'lodash.differencewith';
|
||||
import { Any } 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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { CalendarEventParticipantWithCalendarEventId } from 'src/modules/calendar/common/types/calendar-event';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventParticipantService {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarEventParticipantWorkspaceEntity)
|
||||
private readonly calendarEventParticipantRepository: WorkspaceRepository<CalendarEventParticipantWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
@ -23,8 +21,13 @@ export class CalendarEventParticipantService {
|
||||
participantsToUpdate: CalendarEventParticipantWithCalendarEventId[],
|
||||
transactionManager?: any,
|
||||
): Promise<void> {
|
||||
const calendarEventParticipantRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarEventParticipantWorkspaceEntity>(
|
||||
'calendarEventParticipant',
|
||||
);
|
||||
|
||||
const existingCalendarEventParticipants =
|
||||
await this.calendarEventParticipantRepository.find({
|
||||
await calendarEventParticipantRepository.find({
|
||||
where: {
|
||||
calendarEventId: Any(
|
||||
participantsToUpdate
|
||||
@ -74,7 +77,7 @@ export class CalendarEventParticipantService {
|
||||
participantToUpdate.calendarEventId,
|
||||
);
|
||||
|
||||
await this.calendarEventParticipantRepository.delete(
|
||||
await calendarEventParticipantRepository.delete(
|
||||
{
|
||||
id: Any(
|
||||
calendarEventParticipantsToDelete.map(
|
||||
@ -86,7 +89,7 @@ export class CalendarEventParticipantService {
|
||||
);
|
||||
|
||||
for (const calendarEventParticipantToUpdate of calendarEventParticipantsToUpdate) {
|
||||
await this.calendarEventParticipantRepository.update(
|
||||
await calendarEventParticipantRepository.update(
|
||||
{
|
||||
calendarEventId: calendarEventParticipantToUpdate.calendarEventId,
|
||||
handle: calendarEventParticipantToUpdate.handle,
|
||||
@ -100,7 +103,7 @@ export class CalendarEventParticipantService {
|
||||
|
||||
participantsToSave.push(...newCalendarEventParticipants);
|
||||
|
||||
await this.calendarEventParticipantRepository.save(
|
||||
await calendarEventParticipantRepository.save(
|
||||
participantsToSave,
|
||||
{},
|
||||
transactionManager,
|
||||
@ -113,8 +116,13 @@ export class CalendarEventParticipantService {
|
||||
personId?: string,
|
||||
workspaceMemberId?: string,
|
||||
) {
|
||||
const calendarEventParticipantRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarEventParticipantWorkspaceEntity>(
|
||||
'calendarEventParticipant',
|
||||
);
|
||||
|
||||
const calendarEventParticipantsToUpdate =
|
||||
await this.calendarEventParticipantRepository.find({
|
||||
await calendarEventParticipantRepository.find({
|
||||
where: {
|
||||
handle: email,
|
||||
},
|
||||
@ -124,7 +132,7 @@ export class CalendarEventParticipantService {
|
||||
calendarEventParticipantsToUpdate.map((participant) => participant.id);
|
||||
|
||||
if (personId) {
|
||||
await this.calendarEventParticipantRepository.update(
|
||||
await calendarEventParticipantRepository.update(
|
||||
{
|
||||
id: Any(calendarEventParticipantIdsToUpdate),
|
||||
},
|
||||
@ -136,7 +144,7 @@ export class CalendarEventParticipantService {
|
||||
);
|
||||
|
||||
const updatedCalendarEventParticipants =
|
||||
await this.calendarEventParticipantRepository.find({
|
||||
await calendarEventParticipantRepository.find({
|
||||
where: {
|
||||
id: Any(calendarEventParticipantIdsToUpdate),
|
||||
},
|
||||
@ -149,7 +157,7 @@ export class CalendarEventParticipantService {
|
||||
});
|
||||
}
|
||||
if (workspaceMemberId) {
|
||||
await this.calendarEventParticipantRepository.update(
|
||||
await calendarEventParticipantRepository.update(
|
||||
{
|
||||
id: Any(calendarEventParticipantIdsToUpdate),
|
||||
},
|
||||
@ -168,8 +176,13 @@ export class CalendarEventParticipantService {
|
||||
personId?: string,
|
||||
workspaceMemberId?: string,
|
||||
) {
|
||||
const calendarEventParticipantRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarEventParticipantWorkspaceEntity>(
|
||||
'calendarEventParticipant',
|
||||
);
|
||||
|
||||
if (personId) {
|
||||
await this.calendarEventParticipantRepository.update(
|
||||
await calendarEventParticipantRepository.update(
|
||||
{
|
||||
handle,
|
||||
},
|
||||
@ -179,7 +192,7 @@ export class CalendarEventParticipantService {
|
||||
);
|
||||
}
|
||||
if (workspaceMemberId) {
|
||||
await this.calendarEventParticipantRepository.update(
|
||||
await calendarEventParticipantRepository.update(
|
||||
{
|
||||
handle,
|
||||
},
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
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 { FindManyResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
||||
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
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';
|
||||
|
||||
@ -17,8 +16,7 @@ export class CalendarEventFindManyPreQueryHook
|
||||
implements WorkspaceQueryHookInstance
|
||||
{
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelEventAssociationWorkspaceEntity)
|
||||
private readonly calendarChannelEventAssociationRepository: WorkspaceRepository<CalendarChannelEventAssociationWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly canAccessCalendarEventService: CanAccessCalendarEventService,
|
||||
) {}
|
||||
|
||||
@ -31,8 +29,13 @@ export class CalendarEventFindManyPreQueryHook
|
||||
throw new BadRequestException('id filter is required');
|
||||
}
|
||||
|
||||
const calendarChannelEventAssociationRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
||||
'calendarChannelEventAssociation',
|
||||
);
|
||||
|
||||
const calendarChannelCalendarEventAssociations =
|
||||
await this.calendarChannelEventAssociationRepository.find({
|
||||
await calendarChannelEventAssociationRepository.find({
|
||||
where: {
|
||||
calendarEventId: payload?.filter?.id?.eq,
|
||||
},
|
||||
|
||||
@ -4,8 +4,7 @@ import { WorkspaceQueryHookInstance } from 'src/engine/api/graphql/workspace-que
|
||||
import { FindOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
||||
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
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';
|
||||
|
||||
@ -17,8 +16,7 @@ export class CalendarEventFindOnePreQueryHook
|
||||
implements WorkspaceQueryHookInstance
|
||||
{
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelEventAssociationWorkspaceEntity)
|
||||
private readonly calendarChannelEventAssociationRepository: WorkspaceRepository<CalendarChannelEventAssociationWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly canAccessCalendarEventService: CanAccessCalendarEventService,
|
||||
) {}
|
||||
|
||||
@ -31,9 +29,14 @@ export class CalendarEventFindOnePreQueryHook
|
||||
throw new BadRequestException('id filter is required');
|
||||
}
|
||||
|
||||
const calendarChannelEventAssociationRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
||||
'calendarChannelEventAssociation',
|
||||
);
|
||||
|
||||
// TODO: Re-implement this using twenty ORM
|
||||
const calendarChannelCalendarEventAssociations =
|
||||
await this.calendarChannelEventAssociationRepository.find({
|
||||
await calendarChannelEventAssociationRepository.find({
|
||||
where: {
|
||||
calendarEventId: payload?.filter?.id?.eq,
|
||||
},
|
||||
|
||||
@ -4,23 +4,21 @@ import groupBy from 'lodash.groupby';
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity';
|
||||
import {
|
||||
CalendarChannelVisibility,
|
||||
CalendarChannelWorkspaceEntity,
|
||||
} from 'src/modules/calendar/common/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 {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity)
|
||||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
@InjectObjectMetadataRepository(WorkspaceMemberWorkspaceEntity)
|
||||
@ -32,7 +30,12 @@ export class CanAccessCalendarEventService {
|
||||
workspaceId: string,
|
||||
calendarChannelCalendarEventAssociations: CalendarChannelEventAssociationWorkspaceEntity[],
|
||||
) {
|
||||
const calendarChannels = await this.calendarChannelRepository.find({
|
||||
const calendarRepository =
|
||||
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
|
||||
'calendarChannel',
|
||||
);
|
||||
|
||||
const calendarChannels = await calendarRepository.find({
|
||||
where: {
|
||||
id: Any(
|
||||
calendarChannelCalendarEventAssociations.map(
|
||||
|
||||
@ -4,18 +4,16 @@ import { WorkspaceQueryHookInstance } from 'src/engine/api/graphql/workspace-que
|
||||
import { DeleteOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
||||
|
||||
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 { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/types/object-record-delete.event';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
|
||||
@WorkspaceQueryHook(`connectedAccount.deleteOne`)
|
||||
export class ConnectedAccountDeleteOnePreQueryHook
|
||||
implements WorkspaceQueryHookInstance
|
||||
{
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(MessageChannelWorkspaceEntity)
|
||||
private readonly messageChannelRepository: WorkspaceRepository<MessageChannelWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
@ -26,7 +24,12 @@ export class ConnectedAccountDeleteOnePreQueryHook
|
||||
): Promise<void> {
|
||||
const connectedAccountId = payload.id;
|
||||
|
||||
const messageChannels = await this.messageChannelRepository.findBy({
|
||||
const messageChannelRepository =
|
||||
await this.twentyORMManager.getRepository<MessageChannelWorkspaceEntity>(
|
||||
'messageChannel',
|
||||
);
|
||||
|
||||
const messageChannels = await messageChannelRepository.findBy({
|
||||
connectedAccountId,
|
||||
});
|
||||
|
||||
|
||||
@ -2,22 +2,26 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { EntityManager } 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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
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 { deleteUsingPagination } from 'src/modules/messaging/message-cleaner/utils/delete-using-pagination.util';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingMessageCleanerService {
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(MessageWorkspaceEntity)
|
||||
private readonly messageRepository: WorkspaceRepository<MessageWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(MessageThreadWorkspaceEntity)
|
||||
private readonly messageThreadRepository: WorkspaceRepository<MessageThreadWorkspaceEntity>,
|
||||
) {}
|
||||
constructor(private readonly twentyORMManager: TwentyORMManager) {}
|
||||
|
||||
public async cleanWorkspaceThreads(workspaceId: string) {
|
||||
const messageThreadRepository =
|
||||
await this.twentyORMManager.getRepository<MessageThreadWorkspaceEntity>(
|
||||
'messageThread',
|
||||
);
|
||||
|
||||
const messageRepository =
|
||||
await this.twentyORMManager.getRepository<MessageWorkspaceEntity>(
|
||||
'message',
|
||||
);
|
||||
|
||||
await deleteUsingPagination(
|
||||
workspaceId,
|
||||
500,
|
||||
@ -27,7 +31,7 @@ export class MessagingMessageCleanerService {
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) => {
|
||||
const nonAssociatedMessages = await this.messageRepository.find(
|
||||
const nonAssociatedMessages = await messageRepository.find(
|
||||
{
|
||||
where: {
|
||||
messageChannelMessageAssociations: [],
|
||||
@ -46,7 +50,7 @@ export class MessagingMessageCleanerService {
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) => {
|
||||
await this.messageRepository.delete(ids, transactionManager);
|
||||
await messageRepository.delete(ids, transactionManager);
|
||||
},
|
||||
);
|
||||
|
||||
@ -59,7 +63,7 @@ export class MessagingMessageCleanerService {
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) => {
|
||||
const orphanThreads = await this.messageThreadRepository.find(
|
||||
const orphanThreads = await messageThreadRepository.find(
|
||||
{
|
||||
where: {
|
||||
messages: [],
|
||||
@ -77,7 +81,7 @@ export class MessagingMessageCleanerService {
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) => {
|
||||
await this.messageThreadRepository.delete(ids, transactionManager);
|
||||
await messageThreadRepository.delete(ids, transactionManager);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -5,14 +5,13 @@ import { In } from 'typeorm';
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { MessagingChannelSyncStatusService } from 'src/modules/messaging/common/services/messaging-channel-sync-status.service';
|
||||
import {
|
||||
MessageChannelSyncStage,
|
||||
MessageChannelWorkspaceEntity,
|
||||
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { isSyncStale } from 'src/modules/messaging/message-import-manager/utils/is-sync-stale.util';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { MessagingChannelSyncStatusService } from 'src/modules/messaging/common/services/messaging-channel-sync-status.service';
|
||||
|
||||
export type MessagingOngoingStaleJobData = {
|
||||
workspaceId: string;
|
||||
@ -25,8 +24,7 @@ export type MessagingOngoingStaleJobData = {
|
||||
export class MessagingOngoingStaleJob {
|
||||
private readonly logger = new Logger(MessagingOngoingStaleJob.name);
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(MessageChannelWorkspaceEntity)
|
||||
private readonly messageChannelRepository: WorkspaceRepository<MessageChannelWorkspaceEntity>,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly messagingChannelSyncStatusService: MessagingChannelSyncStatusService,
|
||||
) {}
|
||||
|
||||
@ -34,7 +32,12 @@ export class MessagingOngoingStaleJob {
|
||||
async handle(data: MessagingOngoingStaleJobData): Promise<void> {
|
||||
const { workspaceId } = data;
|
||||
|
||||
const messageChannels = await this.messageChannelRepository.find({
|
||||
const messageChannelRepository =
|
||||
await this.twentyORMManager.getRepository<MessageChannelWorkspaceEntity>(
|
||||
'messageChannel',
|
||||
);
|
||||
|
||||
const messageChannels = await messageChannelRepository.find({
|
||||
where: {
|
||||
syncStage: In([
|
||||
MessageChannelSyncStage.MESSAGES_IMPORT_ONGOING,
|
||||
|
||||
@ -2,8 +2,7 @@ import { WorkspaceQueryHookInstance } from 'src/engine/api/graphql/workspace-que
|
||||
import { DeleteOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
||||
|
||||
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 { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CommentWorkspaceEntity } from 'src/modules/activity/standard-objects/comment.workspace-entity';
|
||||
import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity';
|
||||
|
||||
@ -11,12 +10,7 @@ import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objec
|
||||
export class WorkspaceMemberDeleteOnePreQueryHook
|
||||
implements WorkspaceQueryHookInstance
|
||||
{
|
||||
constructor(
|
||||
@InjectWorkspaceRepository(AttachmentWorkspaceEntity)
|
||||
private readonly attachmentRepository: WorkspaceRepository<AttachmentWorkspaceEntity>,
|
||||
@InjectWorkspaceRepository(CommentWorkspaceEntity)
|
||||
private readonly commentRepository: WorkspaceRepository<CommentWorkspaceEntity>,
|
||||
) {}
|
||||
constructor(private readonly twentyORMManager: TwentyORMManager) {}
|
||||
|
||||
// There is no need to validate the user's access to the workspace member since we don't have permission yet.
|
||||
async execute(
|
||||
@ -24,13 +18,23 @@ export class WorkspaceMemberDeleteOnePreQueryHook
|
||||
workspaceId: string,
|
||||
payload: DeleteOneResolverArgs,
|
||||
): Promise<void> {
|
||||
const attachmentRepository =
|
||||
await this.twentyORMManager.getRepository<AttachmentWorkspaceEntity>(
|
||||
'attachment',
|
||||
);
|
||||
|
||||
const commentRepository =
|
||||
await this.twentyORMManager.getRepository<CommentWorkspaceEntity>(
|
||||
'comment',
|
||||
);
|
||||
|
||||
const authorId = payload.id;
|
||||
|
||||
await this.attachmentRepository.delete({
|
||||
await attachmentRepository.delete({
|
||||
authorId,
|
||||
});
|
||||
|
||||
await this.commentRepository.delete({
|
||||
await commentRepository.delete({
|
||||
authorId,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user