26 lines
820 B
TypeScript
26 lines
820 B
TypeScript
|
import { Mapper } from '@automapper/core';
|
||
|
import { InjectMapper } from '@automapper/nestjs';
|
||
|
import { CommandHandler } from '@nestjs/cqrs';
|
||
|
import { UsersRepository } from '../../adapters/secondaries/users.repository';
|
||
|
import { CreateUserCommand } from '../../commands/create-user.command';
|
||
|
import { CreateUserRequest } from '../dto/create-user.request';
|
||
|
import { User } from '../entities/user';
|
||
|
|
||
|
@CommandHandler(CreateUserCommand)
|
||
|
export class CreateUserUseCase {
|
||
|
constructor(
|
||
|
private readonly _repository: UsersRepository,
|
||
|
@InjectMapper() private readonly _mapper: Mapper,
|
||
|
) {}
|
||
|
|
||
|
async execute(command: CreateUserCommand): Promise<User> {
|
||
|
const entity = this._mapper.map(
|
||
|
command.createUserRequest,
|
||
|
CreateUserRequest,
|
||
|
User,
|
||
|
);
|
||
|
|
||
|
return this._repository.create(entity);
|
||
|
}
|
||
|
}
|