Event listener
Executes logic when a certain event occurs in an entity's lifecycle.
@EventSubscriber()
export class UsersSubscriber implements EntitySubscriberInterface<User> {
constructor(private readonly dataSource: DataSource) {
dataSource.subscribers.push(this);
}
listenTo() {
return User;
}
}async beforeInsert(event: InsertEvent<User>) {
const { entity: user } = event;
user.password = await this.hashingService.hash(user.password);
}Last updated