From 3ef6831d47ed64ad81b82787d452123dd1dca8c6 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Tue, 20 Aug 2024 16:06:34 +0200 Subject: [PATCH] fix wrong payload --- .../listeners/entity-events-to-db.listener.ts | 25 ++++++++----------- .../workspace-event-emitter.ts | 4 +++ .../services/calendar-save-events.service.ts | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/entity-events-to-db.listener.ts b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/entity-events-to-db.listener.ts index d04f342995e3..1804901ac1d5 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/entity-events-to-db.listener.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/entity-events-to-db.listener.ts @@ -50,21 +50,16 @@ export class EntityEventsToDbListener { } private async handle(payload: WorkspaceEventBatch) { - for (const eventPayload of payload.events) { - if (!eventPayload.objectMetadata?.isAuditLogged) { - continue; - } + payload.events = payload.events.filter( + (event) => event.objectMetadata?.isAuditLogged, + ); - await Promise.all([ - this.messageQueueService.add( - CreateAuditLogFromInternalEvent.name, - eventPayload, - ), - this.messageQueueService.add( - UpsertTimelineActivityFromInternalEvent.name, - eventPayload, - ), - ]); - } + await this.messageQueueService.add< + WorkspaceEventBatch + >(CreateAuditLogFromInternalEvent.name, payload); + + await this.messageQueueService.add< + WorkspaceEventBatch + >(UpsertTimelineActivityFromInternalEvent.name, payload); } } diff --git a/packages/twenty-server/src/engine/workspace-event-emitter/workspace-event-emitter.ts b/packages/twenty-server/src/engine/workspace-event-emitter/workspace-event-emitter.ts index e7377e0b9d5d..374bc07c54cb 100644 --- a/packages/twenty-server/src/engine/workspace-event-emitter/workspace-event-emitter.ts +++ b/packages/twenty-server/src/engine/workspace-event-emitter/workspace-event-emitter.ts @@ -8,6 +8,10 @@ export class WorkspaceEventEmitter { constructor(private readonly eventEmitter: EventEmitter2) {} public emit(eventName: string, events: any[], workspaceId: string) { + if (!events.length) { + return; + } + return this.eventEmitter.emit(eventName, { name: eventName, workspaceId, diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-save-events.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-save-events.service.ts index 51f4a8a77e55..bb7b2ab75a69 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-save-events.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-save-events.service.ts @@ -145,7 +145,7 @@ export class CalendarSaveEventsService { [ { workspaceMemberId: connectedAccount.accountOwnerId, - calendarEventParticipants: savedCalendarEventParticipantsToEmit, + participants: savedCalendarEventParticipantsToEmit, }, ], workspaceId,