19 lines
511 B
JavaScript
19 lines
511 B
JavaScript
export class UpdateUserCommandHandler {
|
|
constructor(userRepository) {
|
|
this.userRepository = userRepository;
|
|
}
|
|
|
|
async handle(command) {
|
|
const userData = {};
|
|
if (command.name) userData.name = command.name;
|
|
if (command.email) userData.email = command.email;
|
|
if (command.age !== undefined) userData.age = command.age;
|
|
|
|
const result = await this.userRepository.update(command.id, userData);
|
|
if (!result) {
|
|
throw new Error('User not found');
|
|
}
|
|
return result;
|
|
}
|
|
}
|