user/src/modules/users/domain/usecases/update-user.usecase.ts

26 lines
853 B
TypeScript
Raw Normal View History

2022-12-14 10:37:13 +00:00
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';
2022-12-16 16:31:08 +00:00
import { UpdateUserRequest } from '../dtos/update-user.request';
2022-12-14 10:37:13 +00:00
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<User> {
const entity = this._mapper.map(
command.updateUserRequest,
UpdateUserRequest,
User,
);
return this._repository.update(command.updateUserRequest.uuid, entity);
}
}