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);
}
}