Aggregate Events
Introduction
Aggregate events are triggered when performing aggregate operations.
Types of Events
There are three types of events in the Aggregate:
fetching
: This event is triggered when callingget
,first
,latest
,oldest
orcount
methods.updating
: This event is triggered when callingupdate
method.deleting
: This event is triggered when callingdelete
method.
Accessing Aggregate Events
To access the Aggregate events manager, call the events()
method on the Aggregate class (not the instance)
.
src/app.ts
import { Aggregate } from "@mongez/monpulse";
Aggregate.events()
.onFetching((aggregate) => {
// do something
})
.onUpdating((aggregate) => {
// do something
})
.onDeleting((aggregate) => {
// do something
});