first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { ProjectFactory } from '@task-stream/api/tracker/domain';
|
||||
import { ProjectKeysRepository } from '../ports/project-keys.repository';
|
||||
import { CommandResult, ack } from './command-result';
|
||||
import { CreateProjectCommand } from './create-project.command';
|
||||
|
||||
@CommandHandler(CreateProjectCommand)
|
||||
export class CreateProjectCommandHandler
|
||||
implements ICommandHandler<CreateProjectCommand>
|
||||
{
|
||||
constructor(
|
||||
private readonly projectFactory: ProjectFactory,
|
||||
private readonly projectKeys: ProjectKeysRepository,
|
||||
private readonly eventPublisher: EventPublisher,
|
||||
) {}
|
||||
|
||||
async execute(command: CreateProjectCommand): Promise<CommandResult> {
|
||||
const project = this.projectFactory.create({
|
||||
key: command.key,
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
ownerId: command.actorId,
|
||||
});
|
||||
await this.projectKeys.reserve(project.key, project.id);
|
||||
|
||||
this.eventPublisher.mergeObjectContext(project);
|
||||
await project.commitAndWait();
|
||||
return ack(project);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user