* Add SettingsAccountsEmailsBlocklistInput story * prevent contact creation from the same company * add todo * improvements * Delete packages/twenty-front/src/modules/settings/accounts/components/__stories__/SettingsAccountsEmailsBlocklistInput.stories.tsx * refactor * modify after review * improve code
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
|
|
import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/message-queue-job.interface';
|
|
|
|
import { CreateCompaniesAndContactsService } from 'src/workspace/messaging/services/create-companies-and-contacts/create-companies-and-contacts.service';
|
|
import { MessageChannelService } from 'src/workspace/messaging/repositories/message-channel/message-channel.service';
|
|
import { MessageParticipantService } from 'src/workspace/messaging/repositories/message-participant/message-participant.service';
|
|
|
|
export type CreateCompaniesAndContactsAfterSyncJobData = {
|
|
workspaceId: string;
|
|
messageChannelId: string;
|
|
};
|
|
|
|
@Injectable()
|
|
export class CreateCompaniesAndContactsAfterSyncJob
|
|
implements MessageQueueJob<CreateCompaniesAndContactsAfterSyncJobData>
|
|
{
|
|
private readonly logger = new Logger(
|
|
CreateCompaniesAndContactsAfterSyncJob.name,
|
|
);
|
|
constructor(
|
|
private readonly createCompaniesAndContactsService: CreateCompaniesAndContactsService,
|
|
private readonly messageChannelService: MessageChannelService,
|
|
private readonly messageParticipantService: MessageParticipantService,
|
|
) {}
|
|
|
|
async handle(
|
|
data: CreateCompaniesAndContactsAfterSyncJobData,
|
|
): Promise<void> {
|
|
this.logger.log(
|
|
`create contacts and companies after sync for workspace ${data.workspaceId} and messageChannel ${data.messageChannelId}`,
|
|
);
|
|
const { workspaceId, messageChannelId } = data;
|
|
|
|
const messageChannel = await this.messageChannelService.getByIds(
|
|
[messageChannelId],
|
|
workspaceId,
|
|
);
|
|
|
|
const { handle, isContactAutoCreationEnabled } = messageChannel[0];
|
|
|
|
if (!isContactAutoCreationEnabled) {
|
|
return;
|
|
}
|
|
|
|
const messageParticipantsWithoutPersonIdAndWorkspaceMemberId =
|
|
await this.messageParticipantService.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberIdAndMessageOutgoing(
|
|
messageChannelId,
|
|
workspaceId,
|
|
);
|
|
|
|
await this.createCompaniesAndContactsService.createCompaniesAndContacts(
|
|
handle,
|
|
messageParticipantsWithoutPersonIdAndWorkspaceMemberId,
|
|
workspaceId,
|
|
);
|
|
|
|
await this.messageParticipantService.updateMessageParticipantsAfterPeopleCreation(
|
|
messageParticipantsWithoutPersonIdAndWorkspaceMemberId,
|
|
workspaceId,
|
|
);
|
|
|
|
this.logger.log(
|
|
`create contacts and companies after sync for workspace ${data.workspaceId} and messageChannel ${data.messageChannelId} done`,
|
|
);
|
|
}
|
|
}
|