[messaging] Add messageParticipant matching once people emails are updated (#3887)

* poc nest event emitter

* add match message participant listener

* add workspacemember listener

* fix after review

* fix deep-equal
This commit is contained in:
Weiko
2024-02-08 17:42:33 +01:00
committed by GitHub
parent c53b593ea6
commit 99e2dd6899
19 changed files with 402 additions and 39 deletions

View File

@ -0,0 +1,47 @@
import { Injectable } from '@nestjs/common';
import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/message-queue-job.interface';
import { MessageParticipantService } from 'src/workspace/messaging/message-participant/message-participant.service';
export type MatchMessageParticipantsJobData = {
workspaceId: string;
email: string;
personId?: string;
workspaceMemberId?: string;
};
@Injectable()
export class MatchMessageParticipantJob
implements MessageQueueJob<MatchMessageParticipantsJobData>
{
constructor(
private readonly messageParticipantService: MessageParticipantService,
) {}
async handle(data: MatchMessageParticipantsJobData): Promise<void> {
const { workspaceId, personId, workspaceMemberId, email } = data;
const messageParticipantsToUpdate =
await this.messageParticipantService.getByHandles([email], workspaceId);
const messageParticipantIdsToUpdate = messageParticipantsToUpdate.map(
(participant) => participant.id,
);
if (personId) {
await this.messageParticipantService.updateParticipantsPersonId(
messageParticipantIdsToUpdate,
personId,
workspaceId,
);
}
if (workspaceMemberId) {
await this.messageParticipantService.updateParticipantsWorkspaceMemberId(
messageParticipantIdsToUpdate,
workspaceMemberId,
workspaceId,
);
}
}
}