Add query executed event; forward model events to global event bus
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-05 08:36:35 -05:00
parent 61731c4ebd
commit c264d45927
4 changed files with 91 additions and 1 deletions

View File

@@ -16,13 +16,17 @@ import {ModelUpdatingEvent} from './events/ModelUpdatingEvent'
import {ModelUpdatedEvent} from './events/ModelUpdatedEvent'
import {ModelCreatingEvent} from './events/ModelCreatingEvent'
import {ModelCreatedEvent} from './events/ModelCreatedEvent'
import {EventBus} from '../../event/EventBus'
/**
* Base for classes that are mapped to tables in a database.
*/
export abstract class Model<T extends Model<T>> extends AppClass implements Bus {
@Inject()
protected readonly logging!: Logging;
protected readonly logging!: Logging
@Inject()
protected readonly bus!: EventBus
/**
* The name of the connection this model should run through.
@@ -819,6 +823,8 @@ export abstract class Model<T extends Model<T>> extends AppClass implements Bus
const eventClass: StaticClass<typeof event, typeof event> = event.constructor as StaticClass<Dispatchable, Dispatchable>
await this.modelEventBusSubscribers.where('event', '=', eventClass)
.promiseMap(entry => entry.subscriber(event))
await this.bus.dispatch(event)
}
/**