This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable, NestInterceptor, ExecutionContext, CallHandler, HttpException } from '@nestjs/common'; | |
| import { Observable, throwError } from 'rxjs'; | |
| import { catchError, map } from 'rxjs/operators'; | |
| export interface Response<T> { | |
| data: T; | |
| } | |
| @Injectable() | |
| export class TransformInterceptor<T> implements NestInterceptor<T, Response<T>> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Repository method */ | |
| saveWithTransactions(data, transactionManager): Promise<Entity> { | |
| if (transactionManager) return transactionManager.save(Entity, data); | |
| return this.repository.save(data); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 1. Using DataSource or EntityManager: */ | |
| await myDataSource.manager.transaction(async (transactionalEntityManager) => { | |
| await transactionalEntityManager.save(users) | |
| await transactionalEntityManager.save(photos) | |
| // ... | |
| }); | |
| /* 2. Using a QueryRunner: */ |