Refactor event payload types and event handling
Extracts common event payload interfaces for entity saved, deleted, and audit logged events Improves type safety and reduces code duplication by centralizing event payload definitions
This commit is contained in:
parent
9ea98e3a04
commit
185330402e
3 changed files with 41 additions and 22 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import { ISync, EntityType, SyncStatus } from '../types/CalendarTypes';
|
||||
import { ISync, EntityType, SyncStatus, IEventBus } from '../types/CalendarTypes';
|
||||
import { IEntityService } from './IEntityService';
|
||||
import { SyncPlugin } from './SyncPlugin';
|
||||
import { IndexedDBContext } from './IndexedDBContext';
|
||||
import { IEventBus } from '../types/CalendarTypes';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { diff } from 'json-diff-ts';
|
||||
import { IEntitySavedPayload, IEntityDeletedPayload } from '../types/EventTypes';
|
||||
|
||||
/**
|
||||
* BaseEntityService<T extends ISync> - Abstract base class for all entity services
|
||||
|
|
@ -171,13 +171,14 @@ export abstract class BaseEntityService<T extends ISync> implements IEntityServi
|
|||
|
||||
request.onsuccess = () => {
|
||||
// Emit ENTITY_SAVED event
|
||||
this.eventBus.emit(CoreEvents.ENTITY_SAVED, {
|
||||
const payload: IEntitySavedPayload = {
|
||||
entityType: this.entityType,
|
||||
entityId,
|
||||
operation: isCreate ? 'create' : 'update',
|
||||
changes,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
};
|
||||
this.eventBus.emit(CoreEvents.ENTITY_SAVED, payload);
|
||||
resolve();
|
||||
};
|
||||
|
||||
|
|
@ -201,12 +202,13 @@ export abstract class BaseEntityService<T extends ISync> implements IEntityServi
|
|||
|
||||
request.onsuccess = () => {
|
||||
// Emit ENTITY_DELETED event
|
||||
this.eventBus.emit(CoreEvents.ENTITY_DELETED, {
|
||||
const payload: IEntityDeletedPayload = {
|
||||
entityType: this.entityType,
|
||||
entityId: id,
|
||||
operation: 'delete',
|
||||
timestamp: Date.now()
|
||||
});
|
||||
};
|
||||
this.eventBus.emit(CoreEvents.ENTITY_DELETED, payload);
|
||||
resolve();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue