feat: pay invoice of the free support plan
This commit is contained in:
@@ -518,12 +518,15 @@ export class InvoicesService {
|
||||
|
||||
//*********************************** */
|
||||
|
||||
async payInvoice(invoiceId: string, userId: string) {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
async payInvoice(invoiceId: string, userId: string, queryRunner = this.dataSource.createQueryRunner()) {
|
||||
let transactionStarted = false;
|
||||
|
||||
try {
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
if (!queryRunner.isTransactionActive) {
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
transactionStarted = true;
|
||||
}
|
||||
|
||||
const user = await this.usersService.findOneByIdWithQueryRunner(userId, queryRunner);
|
||||
|
||||
@@ -573,16 +576,17 @@ export class InvoicesService {
|
||||
paidAt: invoice.paidAt,
|
||||
});
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
if (transactionStarted) await queryRunner.commitTransaction();
|
||||
|
||||
return {
|
||||
message: InvoiceMessage.INVOICE_PAID,
|
||||
invoice,
|
||||
};
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
if (transactionStarted) await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
if (transactionStarted) await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user