CQRS Handlers Reference
Command Query Responsibility Segregation patterns in Ever Gauzy.
Overviewβ
Gauzy uses NestJS CQRS (@nestjs/cqrs) to separate write operations (commands) from read operations (queries). This provides:
- Clear separation of concerns
- Easy testing of business logic
- Event-driven side effects
Command Patternβ
Defining a Commandβ
export class CreateOrganizationSprintCommand implements ICommand {
constructor(public readonly input: IOrganizationSprintCreateInput) {}
}
Handling a Commandβ
@CommandHandler(CreateOrganizationSprintCommand)
export class CreateOrganizationSprintHandler implements ICommandHandler<CreateOrganizationSprintCommand> {
constructor(private readonly sprintService: OrganizationSprintService) {}
async execute(command: CreateOrganizationSprintCommand) {
const { input } = command;
return await this.sprintService.create(input);
}
}
Dispatching a Commandβ
@Post('/')
async create(@Body() entity: CreateSprintDTO) {
return await this.commandBus.execute(
new CreateOrganizationSprintCommand(entity)
);
}
Command Flowβ
Common Patternsβ
| Pattern | Description |
|---|---|
| Create commands | Entity creation with side effects |
| Update commands | Entity updates with validation |
| Composite commands | Multi-step operations |
| Event-emitting commands | Trigger events after execution |
Related Pagesβ
- Plugin Development Guide β creating plugins with CQRS
- Architecture Overview β system architecture