Fix event logic for soft-delete and restore (#17393)
This PR changes the shape and logic of SSE events `DELETE` and `RESTORE`, because they behave like `UPDATE` events in practice, they should share the same logic. Before this PR, it was impossible for the frontend to obtain the `deletedAt` value, and the logic to handle soft-delete and restore would have been flawed. Because there is a typing confusion in the parameters of `formatTwentyOrmEventToDatabaseBatchEvent`, due to TypeORM, we also update this util to only accept an array of records, instead of `T | T[]`. We should improve our TypeORM layer in the future. Also the naming was not clear, so we clearly use `recordsAfter` and `recordsBefore` as much as possible, because that is what we have at the end in events. Events are sent from their respective query builders, so these last ones have been updated also. Because TypeORM `soft-remove` operation only returns record ids, we add `.getMany()` to fetch all fields for soft-removed records, so that our event can have before and after.
This commit is contained in:
+4
-4
@@ -1,10 +1,10 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import {
|
||||
ObjectRecordEvent,
|
||||
type ObjectRecordCreateEvent,
|
||||
type ObjectRecordDeleteEvent,
|
||||
type ObjectRecordDestroyEvent,
|
||||
type ObjectRecordNonDestructiveEvent,
|
||||
type ObjectRecordUpdateEvent,
|
||||
type ObjectRecordUpsertEvent,
|
||||
} from 'twenty-shared/database-events';
|
||||
@@ -308,7 +308,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
}
|
||||
|
||||
private async shouldIgnoreEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordNonDestructiveEvent>,
|
||||
payload: WorkspaceEventBatch<ObjectRecordEvent>,
|
||||
) {
|
||||
const workspaceId = payload.workspaceId;
|
||||
const databaseEventName = payload.name;
|
||||
@@ -330,7 +330,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
payload,
|
||||
action,
|
||||
}: {
|
||||
payload: WorkspaceEventBatch<ObjectRecordNonDestructiveEvent>;
|
||||
payload: WorkspaceEventBatch<ObjectRecordEvent>;
|
||||
action: DatabaseEventAction;
|
||||
}) {
|
||||
const workspaceId = payload.workspaceId;
|
||||
@@ -390,7 +390,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
eventListener,
|
||||
action,
|
||||
}: {
|
||||
eventPayload: ObjectRecordNonDestructiveEvent;
|
||||
eventPayload: ObjectRecordEvent;
|
||||
eventListener: WorkflowAutomatedTriggerWorkspaceEntity;
|
||||
action: DatabaseEventAction;
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user