6430 Part 1: remove all raw queries from the messaging and calendar modules (#6572)
Part 1 of #6430 - Remove all repositories which contained raw queries in `messaging` module - Replace them using `twentyORMManager`
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import { Logger, 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 { 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 { MessageChannelMessageAssociationRepository } from 'src/modules/messaging/common/repositories/message-channel-message-association.repository';
|
||||
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { MessagingMessageCleanerService } from 'src/modules/messaging/message-cleaner/services/messaging-message-cleaner.service';
|
||||
|
||||
export type BlocklistItemDeleteMessagesJobData = {
|
||||
@ -25,15 +25,10 @@ export class BlocklistItemDeleteMessagesJob {
|
||||
private readonly logger = new Logger(BlocklistItemDeleteMessagesJob.name);
|
||||
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(MessageChannelWorkspaceEntity)
|
||||
private readonly messageChannelRepository: MessageChannelRepository,
|
||||
@InjectObjectMetadataRepository(
|
||||
MessageChannelMessageAssociationWorkspaceEntity,
|
||||
)
|
||||
private readonly messageChannelMessageAssociationRepository: MessageChannelMessageAssociationRepository,
|
||||
@InjectObjectMetadataRepository(BlocklistWorkspaceEntity)
|
||||
private readonly blocklistRepository: BlocklistRepository,
|
||||
private readonly threadCleanerService: MessagingMessageCleanerService,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
) {}
|
||||
|
||||
@Process(BlocklistItemDeleteMessagesJob.name)
|
||||
@ -65,24 +60,26 @@ export class BlocklistItemDeleteMessagesJob {
|
||||
);
|
||||
}
|
||||
|
||||
const messageChannels =
|
||||
await this.messageChannelRepository.getIdsByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
const messageChannelMessageAssociationRepository =
|
||||
await this.twentyORMManager.getRepository<MessageChannelMessageAssociationWorkspaceEntity>(
|
||||
'messageChannelMessageAssociation',
|
||||
);
|
||||
|
||||
const messageChannelIds = messageChannels.map(({ id }) => id);
|
||||
|
||||
const rolesToDelete: ('from' | 'to')[] = ['from', 'to'];
|
||||
|
||||
for (const messageChannelId of messageChannelIds) {
|
||||
await this.messageChannelMessageAssociationRepository.deleteByMessageParticipantHandleAndMessageChannelIdAndRoles(
|
||||
handle,
|
||||
messageChannelId,
|
||||
rolesToDelete,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
await messageChannelMessageAssociationRepository.delete({
|
||||
messageChannel: {
|
||||
connectedAccount: {
|
||||
accountOwnerId: workspaceMemberId,
|
||||
},
|
||||
},
|
||||
message: {
|
||||
messageParticipants: {
|
||||
handle,
|
||||
role: Any(rolesToDelete),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await this.threadCleanerService.cleanWorkspaceThreads(workspaceId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user