D
Size: a a a
D
K
AL
K
@Injectable
export class UsersService {
constructor(private readonly usersRepository: UsersRepository, private readonly hashPasswordService: HashPasswordService) {}
public async createUser(createUserRequest: CreateUserRequest) : Promise<UserResponse> {
const user = new UserEntity();
//...
user.hashedPassword = await this.hashPasswordService.hash(createUserRequest.password)
//...
await this.usersRepository.save(user);
//...
return userResponse;
}
}
AI
AL
И
K
AI
K
K
EntitySubscriberInterface, который будет работать с DI:@Injectable
export class UserEventsListener implements EntitySubscriberInterface<User> {
constructor(@InjectConnection() private readonly connection: Connection, private readonly hashPasswordService: HashPasswordService) {
connection.subscribers.push(this);
}
public listenTo() {
return User;
}
public async beforeInsert(event: InsertEvent<User>): Promise<void> {
event.entity.password = await this.hashPasswordService.hash(event.entity.password);
}
}
AI
K
AI
AL
K
IS
AL
K