6619 modify event emitter to emit an array of events (#6625)
Closes #6619 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
|
||||
import { Any } from 'typeorm';
|
||||
|
||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
@ -17,7 +17,7 @@ export class MatchParticipantService<
|
||||
| MessageParticipantWorkspaceEntity,
|
||||
> {
|
||||
constructor(
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
private readonly workspaceEventEmitter: WorkspaceEventEmitter,
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly scopedWorkspaceContextFactory: ScopedWorkspaceContextFactory,
|
||||
) {}
|
||||
@ -46,6 +46,10 @@ export class MatchParticipantService<
|
||||
|
||||
const workspaceId = this.scopedWorkspaceContextFactory.create().workspaceId;
|
||||
|
||||
if (!workspaceId) {
|
||||
throw new Error('Workspace ID is required');
|
||||
}
|
||||
|
||||
const participantIds = participants.map((participant) => participant.id);
|
||||
const uniqueParticipantsHandles = [
|
||||
...new Set(participants.map((participant) => participant.handle)),
|
||||
@ -109,11 +113,16 @@ export class MatchParticipantService<
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
this.eventEmitter.emit(`${objectMetadataName}.matched`, {
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataName}.matched`,
|
||||
[
|
||||
{
|
||||
workspaceMemberId: null,
|
||||
participants: matchedParticipants,
|
||||
},
|
||||
],
|
||||
workspaceId,
|
||||
workspaceMemberId: null,
|
||||
participants: matchedParticipants,
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
public async matchParticipantsAfterPersonOrWorkspaceMemberCreation(
|
||||
@ -127,6 +136,10 @@ export class MatchParticipantService<
|
||||
|
||||
const workspaceId = this.scopedWorkspaceContextFactory.create().workspaceId;
|
||||
|
||||
if (!workspaceId) {
|
||||
throw new Error('Workspace ID is required');
|
||||
}
|
||||
|
||||
const participantsToUpdate = await participantRepository.find({
|
||||
where: {
|
||||
handle,
|
||||
@ -155,12 +168,18 @@ export class MatchParticipantService<
|
||||
},
|
||||
});
|
||||
|
||||
this.eventEmitter.emit(`${objectMetadataName}.matched`, {
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataName}.matched`,
|
||||
[
|
||||
{
|
||||
workspaceId,
|
||||
name: `${objectMetadataName}.matched`,
|
||||
workspaceMemberId: null,
|
||||
participants: updatedParticipants,
|
||||
},
|
||||
],
|
||||
workspaceId,
|
||||
name: `${objectMetadataName}.matched`,
|
||||
workspaceMemberId: null,
|
||||
participants: updatedParticipants,
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
if (workspaceMemberId) {
|
||||
|
||||
Reference in New Issue
Block a user