4736 add listener on calendarchannel isautocontactcreationenabled (#4913)

Closes #4736
This commit is contained in:
bosiraphael
2024-04-11 17:57:19 +02:00
committed by GitHub
parent 7211730570
commit 8853408264
11 changed files with 186 additions and 62 deletions

View File

@ -6,33 +6,31 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos
import { CreateCompanyAndContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service';
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
import { MessageParticipantRepository } from 'src/modules/messaging/repositories/message-participant.repository';
import { MessageParticipantService } from 'src/modules/messaging/services/message-participant/message-participant.service';
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
export type CreateCompaniesAndContactsAfterSyncJobData = {
export type MessagingCreateCompanyAndContactAfterSyncJobData = {
workspaceId: string;
messageChannelId: string;
};
@Injectable()
export class CreateCompaniesAndContactsAfterSyncJob
implements MessageQueueJob<CreateCompaniesAndContactsAfterSyncJobData>
export class MessagingCreateCompanyAndContactAfterSyncJob
implements MessageQueueJob<MessagingCreateCompanyAndContactAfterSyncJobData>
{
private readonly logger = new Logger(
CreateCompaniesAndContactsAfterSyncJob.name,
MessagingCreateCompanyAndContactAfterSyncJob.name,
);
constructor(
private readonly createCompaniesAndContactsService: CreateCompanyAndContactService,
private readonly createCompanyAndContactService: CreateCompanyAndContactService,
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
private readonly messageChannelService: MessageChannelRepository,
private readonly messageParticipantService: MessageParticipantService,
@InjectObjectMetadataRepository(MessageParticipantObjectMetadata)
private readonly messageParticipantRepository: MessageParticipantRepository,
) {}
async handle(
data: CreateCompaniesAndContactsAfterSyncJobData,
data: MessagingCreateCompanyAndContactAfterSyncJobData,
): Promise<void> {
this.logger.log(
`create contacts and companies after sync for workspace ${data.workspaceId} and messageChannel ${data.messageChannelId}`,
@ -50,20 +48,15 @@ export class CreateCompaniesAndContactsAfterSyncJob
return;
}
const messageParticipantsWithoutPersonIdAndWorkspaceMemberId =
const contactsToCreate =
await this.messageParticipantRepository.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberIdAndMessageOutgoing(
messageChannelId,
workspaceId,
);
await this.createCompaniesAndContactsService.createCompaniesAndContacts(
await this.createCompanyAndContactService.createCompaniesAndContactsAndUpdateParticipants(
handle,
messageParticipantsWithoutPersonIdAndWorkspaceMemberId,
workspaceId,
);
await this.messageParticipantService.updateMessageParticipantsAfterPeopleCreation(
messageParticipantsWithoutPersonIdAndWorkspaceMemberId,
contactsToCreate,
workspaceId,
);

View File

@ -42,7 +42,7 @@ export class MessagingConnectedAccountListener {
value: true,
});
this.messageQueueService.add<DeleteConnectedAccountAssociatedMessagingDataJobData>(
await this.messageQueueService.add<DeleteConnectedAccountAssociatedMessagingDataJobData>(
DeleteConnectedAccountAssociatedMessagingDataJob.name,
{
workspaceId: payload.workspaceId,
@ -51,7 +51,7 @@ export class MessagingConnectedAccountListener {
);
if (isCalendarEnabled) {
this.calendarQueueService.add<DeleteConnectedAccountAssociatedCalendarDataJobData>(
await this.calendarQueueService.add<DeleteConnectedAccountAssociatedCalendarDataJobData>(
DeleteConnectedAccountAssociatedCalendarDataJob.name,
{
workspaceId: payload.workspaceId,

View File

@ -6,9 +6,9 @@ import { objectRecordChangedProperties } from 'src/engine/integrations/event-emi
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
import {
CreateCompaniesAndContactsAfterSyncJobData,
CreateCompaniesAndContactsAfterSyncJob,
} from 'src/modules/messaging/jobs/create-companies-and-contacts-after-sync.job';
MessagingCreateCompanyAndContactAfterSyncJobData,
MessagingCreateCompanyAndContactAfterSyncJob,
} from 'src/modules/messaging/jobs/messaging-create-company-and-contact-after-sync.job';
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
@Injectable()
@ -19,7 +19,7 @@ export class MessagingMessageChannelListener {
) {}
@OnEvent('messageChannel.updated')
handleUpdatedEvent(
async handleUpdatedEvent(
payload: ObjectRecordUpdateEvent<MessageChannelObjectMetadata>,
) {
if (
@ -29,8 +29,8 @@ export class MessagingMessageChannelListener {
).includes('isContactAutoCreationEnabled') &&
payload.details.after.isContactAutoCreationEnabled
) {
this.messageQueueService.add<CreateCompaniesAndContactsAfterSyncJobData>(
CreateCompaniesAndContactsAfterSyncJob.name,
await this.messageQueueService.add<MessagingCreateCompanyAndContactAfterSyncJobData>(
MessagingCreateCompanyAndContactAfterSyncJob.name,
{
workspaceId: payload.workspaceId,
messageChannelId: payload.recordId,

View File

@ -3,10 +3,7 @@ import { Injectable } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import {
ParticipantWithId,
ParticipantWithMessageId,
} from 'src/modules/messaging/types/gmail-message';
import { ParticipantWithMessageId } from 'src/modules/messaging/types/gmail-message';
import { PersonRepository } from 'src/modules/person/repositories/person.repository';
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
@ -27,10 +24,14 @@ export class MessageParticipantService {
) {}
public async updateMessageParticipantsAfterPeopleCreation(
participants: ParticipantWithId[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
const participants =
await this.messageParticipantRepository.getWithoutPersonIdAndWorkspaceMemberId(
workspaceId,
);
if (!participants) return;
const dataSourceSchema =