My system has a layered architecture - controller, service and repository.
I put my business logic in the service layer. And services are reused and deligated among other services.
My repository extends Typeorm's repository and it is highly decoupled.
Controlling transaction in Typeorm needs a new manager(transactionManager) which is not instantiated and injected by NestJS container. In circumstances where multiple services need to be run in a single transaction, currently, I have no idea how to do it.
My code snippet is below.
@Injectable()
export class PaymentService {
constructor(
private readonly paymentHistoryService: PaymentHistoryService,
private readonly orderService:OrderService){}
@Transaction()
async confirmRequest(orderId: string,
@TransactionRepository(Order) orderRepo?: OrderRepository,
@TransactionRepository(PaymentHistory) paymentHistoryRepo?:PaymentHistoryRepository)
: Promise<Order> {
// I cannot use paymentHistoryService and orderService to run in a single transaction.
// New repository instance which supports transaction features need to be instantiated.
}
}
Any ideas?
Thanks!
According to this issue https://github.com/typeorm/typeorm/issues/3251, transaction decorators might be removed in the future, so I'd rather suggest using EntityManager or QueryRunner to manage transactions.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.