Skip to content

Commit

Permalink
Merge branch 'underfisk-underfisk/cqrs-docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Aug 20, 2020
2 parents 5ea06ab + 71e3e12 commit 87f88e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/decorators/command-handler.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import 'reflect-metadata';
import { ICommand } from '../index';
import { COMMAND_HANDLER_METADATA } from './constants';

/**
* Decorator that marks a class as a Nest command handler. A command handler
* handles commands (actions) executed by your application code.
*
* The decorated class must implement the `ICommandHandler` interface.
*
* @param command command *type* to be handled by this handler.
*
* @see https://docs.nestjs.com/recipes/cqrs#commands
*/
export const CommandHandler = (command: ICommand): ClassDecorator => {
return (target: object) => {
Reflect.defineMetadata(COMMAND_HANDLER_METADATA, command, target);
Expand Down
10 changes: 10 additions & 0 deletions src/decorators/events-handler.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import 'reflect-metadata';
import { IEvent } from '../index';
import { EVENTS_HANDLER_METADATA } from './constants';

/**
* Decorator that marks a class as a Nest event handler. An event handler
* handles events executed by your application code.
*
* The decorated class must implement the `IEventHandler` interface.
*
* @param events one or more event *types* to be handled by this handler.
*
* @see https://docs.nestjs.com/recipes/cqrs#events
*/
export const EventsHandler = (...events: IEvent[]): ClassDecorator => {
return (target: object) => {
Reflect.defineMetadata(EVENTS_HANDLER_METADATA, events, target);
Expand Down
10 changes: 10 additions & 0 deletions src/decorators/query-handler.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import 'reflect-metadata';
import { IQuery } from '../interfaces';
import { QUERY_HANDLER_METADATA } from './constants';

/**
* Decorator that marks a class as a Nest query handler. A query handler
* handles queries executed by your application code.
*
* The decorated class must implement the `IQueryHandler` interface.
*
* @param query query *type* to be handled by this handler.
*
* @see https://docs.nestjs.com/recipes/cqrs#queries
*/
export const QueryHandler = (query: IQuery): ClassDecorator => {
return (target: object) => {
Reflect.defineMetadata(QUERY_HANDLER_METADATA, query, target);
Expand Down
5 changes: 5 additions & 0 deletions src/decorators/saga.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'reflect-metadata';
import { SAGA_METADATA } from './constants';

/**
* Decorator that marks a class as a Nest saga. Sagas may listen and react to 1..N events.
*
* @see https://docs.nestjs.com/recipes/cqrs#sagas
*/
export const Saga = (): PropertyDecorator => {
return (target: object, propertyKey: string | symbol) => {
const properties =
Expand Down

0 comments on commit 87f88e1

Please sign in to comment.