Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
research-tool social-network tools-for-thought atproto
Something went wrong. Try again.
TypeScript
at development
12345678910111213141516171819202122232425262728293031323334import { IEventPublisher } from '../application/events/IEventPublisher';import { AggregateRoot } from '../domain/AggregateRoot';import { Result, ok } from './Result';
export interface UseCase<IRequest, IResponse> { execute(request?: IRequest): Promise<IResponse> | IResponse;}
export abstract class BaseUseCase<IRequest, IResponse> implements UseCase<IRequest, IResponse>{ constructor(protected eventPublisher: IEventPublisher) {}
abstract execute(request?: IRequest): Promise<IResponse> | IResponse;
protected async publishEventsForAggregate( aggregate: AggregateRoot<any>, ): Promise<Result<void>> { const events = aggregate.domainEvents;
if (events.length === 0) { return ok(undefined); }
const publishResult = await this.eventPublisher.publishEvents(events);
if (publishResult.isOk()) { aggregate.clearEvents(); }
return publishResult; }}