Skip to content

Commit

Permalink
feat: ORV2-2530 Get endpoint to handle Credit account users (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Jul 5, 2024
1 parent 05d5023 commit 7942245
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions vehicles/src/modules/credit-account/credit-account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ export class CreditAccountService {
}

@LogAsyncMethodExecution()
async getCreditAccount(currentUser: IUserJWT, companyId: number) {
//TODO handle where company is Credit Account User.
const creditAccount = await this.creditAccountRepository.findOne({
async getCreditAccount(currentUser: IUserJWT, companyId: number) {
let creditAccount = await this.creditAccountRepository.findOne({
where: {
company: { companyId },
},
Expand All @@ -254,6 +253,23 @@ export class CreditAccountService {
creditAccountActivities: { idirUser: true },
},
});

if (
!creditAccount ||
creditAccount?.creditAccountStatusType ===
CreditAccountStatus.ACCOUNT_CLOSED
) {
creditAccount = await this.creditAccountRepository.findOne({
where: {
creditAccountUsers: { company: { companyId }, isActive: true },
},
relations: {
company: true,
creditAccountUsers: { company: true },
creditAccountActivities: { idirUser: true },
},
});
}
if (!creditAccount) {
throw new DataNotFoundException();
}
Expand Down

0 comments on commit 7942245

Please sign in to comment.