◾️ Example Flow (Problem with preprocessing using @BeforeUpdate() annotation)
- call save() -> process hook method -> update db
- call update() -> (without processing hook method) -> update db
◾️ this hooking method is called when we create/update db
.......
@BeforeInsert()
@BeforeUpdate()
async handleHook(): Promise<void> {
<do something...>
}
.......
◾️ update processed without calling hook because send query directly without using entity
.....
async updateUser(id:number, userInput:UserInput) {
<skip content....>
return await this.users.update(user);
}
.....
◾️ save() processed with calling hook method because it use entity
.....
async updateUser(id:number, userInput:UserInput) {
<skip content....>
return await this.users.save(user);
}
.....