Skip to content

Commit

Permalink
ORV2-2886 Fix Connection deadlock in findPermitHistory() (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Jan 9, 2025
1 parent 140e50a commit 2f871f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
} from 'typeorm';
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
import { AutoMap } from '@automapper/classes';
import { Base } from '../../../common/entities/base.entity';
import { Transaction } from './transaction.entity';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export class PaymentService {
createTransactionDto,
existingApplications,
currentUser,
queryRunner,
);
const transactionOrderNumber =
await this.generateTransactionOrderNumber();
Expand Down Expand Up @@ -555,6 +556,7 @@ export class PaymentService {
createTransactionDto: CreateTransactionDto,
applications: Permit[],
currentUser: IUserJWT,
queryRunner: QueryRunner,
) {
let totalTransactionAmountCalculated = 0;
const isCVClientUser: boolean = isCVClient(currentUser.identity_provider);
Expand All @@ -569,8 +571,10 @@ export class PaymentService {
`Atleast one of the application has invalid startDate or expiryDate.`,
);
}
totalTransactionAmountCalculated +=
await this.permitFeeCalculator(application);
totalTransactionAmountCalculated += await this.permitFeeCalculator(
application,
queryRunner,
);
}
const totalTransactionAmount =
createTransactionDto.applicationDetails?.reduce(
Expand Down Expand Up @@ -852,12 +856,17 @@ export class PaymentService {
* @param queryRunner - An optional QueryRunner for database transactions.
* @returns {Promise<number>} - The calculated permit fee or refund amount.
*/
async permitFeeCalculator(application: Permit): Promise<number> {
@LogAsyncMethodExecution()
async permitFeeCalculator(
application: Permit,
queryRunner?: QueryRunner,
): Promise<number> {
if (application.permitStatus === ApplicationStatus.REVOKED) return 0;
const companyId = application.company.companyId;

const permitPaymentHistory = await this.findPermitHistory(
application.originalPermitId,
queryRunner,
companyId,
);
const isNoFee = await this.specialAuthService.findNoFee(companyId);
Expand All @@ -876,10 +885,13 @@ export class PaymentService {
@LogAsyncMethodExecution()
public async findPermitHistory(
originalPermitId: string,
queryRunner: QueryRunner,
companyId?: number,
): Promise<PermitHistoryDto[]> {
const permits = await this.permitRepository
.createQueryBuilder('permit')
const permits = await queryRunner.manager
.createQueryBuilder()
.select('permit')
.from(Permit, 'permit')
.leftJoinAndSelect('permit.company', 'company')
.innerJoinAndSelect('permit.permitTransactions', 'permitTransactions')
.innerJoinAndSelect('permitTransactions.transaction', 'transaction')
Expand Down

0 comments on commit 2f871f3

Please sign in to comment.