NestJS - Database with TypeORM
You want to update two related entities atomically in NestJS using TypeORM transactions. Which approach correctly ensures both updates succeed or fail together?
async updateEntities(entityA, entityB) {
await this.dataSource.transaction(async (manager) => {
await manager.save(entityA);
await manager.save(entityB);
});
}
What is the best practice to handle errors and maintain data consistency?