From 79422453833828ca1702342ef7e6efd9c26f45eb Mon Sep 17 00:00:00 2001 From: Praveen Raju <80779423+praju-aot@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:56:56 -0400 Subject: [PATCH] feat: ORV2-2530 Get endpoint to handle Credit account users (#1461) --- .../credit-account/credit-account.service.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vehicles/src/modules/credit-account/credit-account.service.ts b/vehicles/src/modules/credit-account/credit-account.service.ts index 5d371f983..9990f4ab6 100644 --- a/vehicles/src/modules/credit-account/credit-account.service.ts +++ b/vehicles/src/modules/credit-account/credit-account.service.ts @@ -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 }, }, @@ -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(); }