Aller au contenu principal

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

PatternDescription
Create commandsEntity creation with side effects
Update commandsEntity updates with validation
Composite commandsMulti-step operations
Event-emitting commandsTrigger events after execution