Closes #4738 - Added the logic to unmatch a participant when the email of a person or a workspace member is updated
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
import { MessageQueueJob } from 'src/engine/integrations/message-queue/interfaces/message-queue-job.interface';
|
|
|
|
import {
|
|
FeatureFlagEntity,
|
|
FeatureFlagKeys,
|
|
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
|
import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service';
|
|
import { MessageParticipantService } from 'src/modules/messaging/services/message-participant/message-participant.service';
|
|
|
|
export type MatchParticipantJobData = {
|
|
workspaceId: string;
|
|
email: string;
|
|
personId?: string;
|
|
workspaceMemberId?: string;
|
|
};
|
|
|
|
@Injectable()
|
|
export class MatchParticipantJob
|
|
implements MessageQueueJob<MatchParticipantJobData>
|
|
{
|
|
constructor(
|
|
private readonly messageParticipantService: MessageParticipantService,
|
|
private readonly calendarEventParticipantService: CalendarEventParticipantService,
|
|
@InjectRepository(FeatureFlagEntity, 'core')
|
|
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
|
) {}
|
|
|
|
async handle(data: MatchParticipantJobData): Promise<void> {
|
|
const { workspaceId, email, personId, workspaceMemberId } = data;
|
|
|
|
await this.messageParticipantService.matchMessageParticipants(
|
|
workspaceId,
|
|
email,
|
|
personId,
|
|
workspaceMemberId,
|
|
);
|
|
|
|
const isCalendarEnabled = await this.featureFlagRepository.findOneBy({
|
|
workspaceId,
|
|
key: FeatureFlagKeys.IsCalendarEnabled,
|
|
value: true,
|
|
});
|
|
|
|
if (!isCalendarEnabled || !isCalendarEnabled.value) {
|
|
return;
|
|
}
|
|
|
|
await this.calendarEventParticipantService.matchCalendarEventParticipants(
|
|
workspaceId,
|
|
email,
|
|
personId,
|
|
workspaceMemberId,
|
|
);
|
|
}
|
|
}
|