I am trying to implement transactions in nestjs with this package typeorm-transactional-cls-hooked.
@Transactional()
async addUser(id: string){
await this.userService.deleteIfExist(id)
const user = this.userService.createUser()
await this.addUserProfile()
await this.addUserMeta()
}
async addUserProfile(){
await this.addUserMeta()
return this.userProfile.createProfile() // this call can fail for any reason
}
async addUserMeta(){
return this.userMetaService.addUserMeta() // this call can fail for any reason
}
I want to wrap all these functions in a single transaction, I tried with transactional decorator but what happens is, in case addUserMeta calls fail still all operations are not rollbacked. How atomicity can be achieved with this?