import { Mapper } from '@automapper/core'; import { InjectMapper } from '@automapper/nestjs'; import { CommandHandler } from '@nestjs/cqrs'; import { UsersRepository } from '../../adapters/secondaries/users.repository'; import { UpdateUserCommand } from '../../commands/update-user.command'; import { UpdateUserRequest } from '../dto/update-user.request'; import { User } from '../entities/user'; @CommandHandler(UpdateUserCommand) export class UpdateUserUseCase { constructor( private readonly _repository: UsersRepository, @InjectMapper() private readonly _mapper: Mapper, ) {} async execute(command: UpdateUserCommand): Promise { const entity = this._mapper.map( command.updateUserRequest, UpdateUserRequest, User, ); return this._repository.update(command.updateUserRequest.uuid, entity); } }