28 lines
1.2 KiB
JavaScript
28 lines
1.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.UpdateUserCommandHandler = void 0;
|
|
const UserMapper_1 = require("../../DTOs/Mappers/UserMapper");
|
|
const PasswordService_1 = require("../../Services/PasswordService");
|
|
class UpdateUserCommandHandler {
|
|
constructor(userRepo) {
|
|
this.userRepo = userRepo;
|
|
}
|
|
async execute(cmd) {
|
|
const updateData = { ...cmd };
|
|
// Hash the password if it's being updated
|
|
if (cmd.password) {
|
|
// Validate password strength
|
|
const passwordValidation = PasswordService_1.PasswordService.validatePasswordStrength(cmd.password);
|
|
if (!passwordValidation.isValid) {
|
|
throw new Error(`Password validation failed: ${passwordValidation.errors.join(', ')}`);
|
|
}
|
|
updateData.password = await PasswordService_1.PasswordService.hashPassword(cmd.password);
|
|
}
|
|
const updated = await this.userRepo.update(cmd.id, updateData);
|
|
if (!updated)
|
|
return null;
|
|
return UserMapper_1.UserMapper.toShortDto(updated);
|
|
}
|
|
}
|
|
exports.UpdateUserCommandHandler = UpdateUserCommandHandler;
|
|
//# sourceMappingURL=UpdateUserCommandHandler.js.map
|