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.
14 lines
381 B
TypeScript
14 lines
381 B
TypeScript
import { type ObjectRecordDiff } from '@/database-events/object-record-diff';
|
|
import { ObjectRecordBaseEvent } from '@/database-events/object-record.base.event';
|
|
|
|
export class ObjectRecordUpdateEvent<
|
|
T = object,
|
|
> extends ObjectRecordBaseEvent<T> {
|
|
declare properties: {
|
|
updatedFields: string[];
|
|
diff: Partial<ObjectRecordDiff<T>>;
|
|
before: T;
|
|
after: T;
|
|
};
|
|
}
|