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:
@ -7,6 +7,7 @@ import { ObjectRecordUpdateEvent } from 'src/engine/integrations/event-emitter/t
|
||||
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/workspace-event.type';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import {
|
||||
BlocklistItemDeleteCalendarEventsJob,
|
||||
@ -26,48 +27,74 @@ export class CalendarBlocklistListener {
|
||||
|
||||
@OnEvent('blocklist.created')
|
||||
async handleCreatedEvent(
|
||||
payload: ObjectRecordCreateEvent<BlocklistWorkspaceEntity>,
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<BlocklistWorkspaceEntity>
|
||||
>,
|
||||
) {
|
||||
await this.messageQueueService.add<BlocklistItemDeleteCalendarEventsJobData>(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: payload.recordId,
|
||||
},
|
||||
await Promise.all(
|
||||
payload.events.map((eventPayload) =>
|
||||
this.messageQueueService.add<BlocklistItemDeleteCalendarEventsJobData>(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: eventPayload.recordId,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.deleted')
|
||||
async handleDeletedEvent(
|
||||
payload: ObjectRecordDeleteEvent<BlocklistWorkspaceEntity>,
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<BlocklistWorkspaceEntity>
|
||||
>,
|
||||
) {
|
||||
await this.messageQueueService.add<BlocklistReimportCalendarEventsJobData>(
|
||||
BlocklistReimportCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId: payload.properties.before.workspaceMember.id,
|
||||
},
|
||||
await Promise.all(
|
||||
payload.events.map((eventPayload) =>
|
||||
this.messageQueueService.add<BlocklistReimportCalendarEventsJobData>(
|
||||
BlocklistReimportCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId:
|
||||
eventPayload.properties.before.workspaceMember.id,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.updated')
|
||||
async handleUpdatedEvent(
|
||||
payload: ObjectRecordUpdateEvent<BlocklistWorkspaceEntity>,
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<BlocklistWorkspaceEntity>
|
||||
>,
|
||||
) {
|
||||
await this.messageQueueService.add<BlocklistItemDeleteCalendarEventsJobData>(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: payload.recordId,
|
||||
},
|
||||
);
|
||||
await Promise.all(
|
||||
payload.events.reduce((acc: Promise<void>[], eventPayload) => {
|
||||
acc.push(
|
||||
this.messageQueueService.add<BlocklistItemDeleteCalendarEventsJobData>(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: eventPayload.recordId,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await this.messageQueueService.add<BlocklistReimportCalendarEventsJobData>(
|
||||
BlocklistReimportCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId: payload.properties.after.workspaceMember.id,
|
||||
},
|
||||
acc.push(
|
||||
this.messageQueueService.add<BlocklistReimportCalendarEventsJobData>(
|
||||
BlocklistReimportCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId:
|
||||
eventPayload.properties.after.workspaceMember.id,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return acc;
|
||||
}, []),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user