I am currently utilizing cqrs with nestjs
Within my setup, I have a saga that essentially consists of rxjs implementations
@Saga()
updateEvent = (events$: Observable<any>): Observable<ICommand> => {
return events$.pipe(
ofType(UpdatedEvent,),
map((event) => {
return new otherCommand(event);
})
);
};
}
The dilemma at hand is: How can I merge Events that all share the same superclass? Ideally, I would like just one saga to capture all events rather than having a separate saga for each event.
I attempted the following:
ofType(UpdatedEvent,CreateEvent,DeleteEvent),
However, this approach did not yield the desired result and TypeScript flagged it as an issue due to the generic type, resulting in the error:
right-hand side of 'instanceof' is not callable
My events are structured as follows:
class UpdateEvent extends Base<UpdateDto>{
constructor(){super()}
}
class CreateEvent extends Base<CreateDto>{
constructor(){super()}
}
The main distinction between these events lies in the Dtos they use.