Skip to content

Commit

Permalink
fix: Credit Account ORV2-2507,2508,2509,2510 (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Jun 25, 2024
1 parent ff1fa8f commit cc657a8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
16 changes: 16 additions & 0 deletions database/mssql/scripts/sampledata/dbo.ORBC_FEATURE_FLAG.Table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET NOCOUNT ON
GO
SET IDENTITY_INSERT [dbo].[ORBC_FEATURE_FLAG] ON

INSERT INTO [dbo].[ORBC_FEATURE_FLAG] ([FEATURE_ID]
,[FEATURE_KEY]
,[FEATURE_VALUE]
,[CONCURRENCY_CONTROL_NUMBER]
,[DB_CREATE_USERID]
,[DB_CREATE_TIMESTAMP]
,[DB_LAST_UPDATE_USERID]
,[DB_LAST_UPDATE_TIMESTAMP])
VALUES ('1','CREDIT-ACCOUNT','ENABLED', NULL, N'dbo', GETUTCDATE(), N'dbo', GETUTCDATE());

SET IDENTITY_INSERT [dbo].[ORBC_FEATURE_FLAG] OFF
GO
2 changes: 2 additions & 0 deletions database/mssql/scripts/utility/refresh-sample-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ USAGE="-u ORBC_USER -p ORBC_PASS -s ORBC_SERVER -d ORBC_DATABASE"
parse_options "${USAGE}" ${@}

echo "Deleting existing sample data"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_FEATURE_FLAG"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_TRAILER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_POWER_UNIT"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_COMPANY_USER"
Expand All @@ -23,5 +24,6 @@ sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -i ${SCRIPT_DIR}/sampledata/dbo.ORBC_COMPANY_USER.Table.sql
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -i ${SCRIPT_DIR}/sampledata/dbo.ORBC_POWER_UNIT.Table.sql
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -i ${SCRIPT_DIR}/sampledata/dbo.ORBC_TRAILER.Table.sql
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -i ${SCRIPT_DIR}/sampledata/dbo.ORBC_FEATURE_FLAG.Table.sql

echo "Finished loading sample data"
4 changes: 4 additions & 0 deletions vehicles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ MSSQL_DB=
MSSQL_SA_USER=
MSSQL_SA_PASSWORD=
MSSQL_ENCRYPT=
BCGOV_FAX_EMAIL=<faxnumber>@<domain>
CFS_CREDIT_ACCOUNT_URL=
CFS_CREDIT_ACCOUNT_CLIENT_ID=
CFS_CREDIT_ACCOUNT_CLIENT_SECRET=
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class CompanyService {
/**
* The findOne() method returns a ReadCompanyDto object corresponding to the
* company with that Id. It retrieves the entity from the database using the
* Repository, maps it to a DTO object using the Mapper, and returns it.
* findOneEntity(), maps it to a DTO object using the Mapper, and returns it.
*
* @param companyId The company Id.
*
Expand All @@ -340,18 +340,31 @@ export class CompanyService {
@LogAsyncMethodExecution()
async findOne(companyId: number): Promise<ReadCompanyDto> {
return this.classMapper.mapAsync(
await this.companyRepository.findOne({
where: { companyId: companyId },
relations: {
mailingAddress: true,
primaryContact: true,
},
}),
await this.findOneEntity(companyId),
Company,
ReadCompanyDto,
);
}

/**
* The findOne() method returns the Company Entity object corresponding to the
* company with that Id.
*
* @param companyId The company Id.
*
* @returns The company details as a promise of type {@link ReadCompanyDto}
*/
@LogAsyncMethodExecution()
async findOneEntity(companyId: number): Promise<Company> {
return await this.companyRepository.findOne({
where: { companyId: companyId },
relations: {
mailingAddress: true,
primaryContact: true,
},
});
}

/**
* The findOneCompanyWithAllDetails() method returns the Company entity
* corresponding to the specified companyId. It retrieves the entity from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { IsFeatureFlagEnabled } from '../../common/decorator/is-feature-flag-ena
description: 'The Credit Account Users Api Internal Server Error Response',
type: ExceptionDto,
})
@IsFeatureFlagEnabled('CREDIT-ACCOUNT')
@Controller(
'companies/:companyId/credit-account/:creditAccountId/credit-account-user',
)
Expand All @@ -63,9 +64,8 @@ export class CreditAccountUserController {
})
@ApiCreatedResponse({
description: 'The result of the changes to the credit account user.',
type: String,
type: ReadCreditAccountUserDto,
})
@IsFeatureFlagEnabled('CREDIT-ACCOUNT')
@Put()
@Roles(Role.WRITE_CREDIT_ACCOUNT)
async addOrActivateCreditAccountUser(
Expand Down Expand Up @@ -95,11 +95,10 @@ export class CreditAccountUserController {
description:
'Deactivates one or more credit account user, enforcing authentication.',
})
@ApiCreatedResponse({
description: 'The result of the changes to the credit account user.',
type: String,
@ApiOkResponse({
description: 'The result of the delete operation of credit account user.',
type: DeleteDto,
})
@IsFeatureFlagEnabled('CREDIT-ACCOUNT')
@Delete()
@Roles(Role.WRITE_CREDIT_ACCOUNT)
async deactivateCreditAccountUser(
Expand Down Expand Up @@ -132,7 +131,6 @@ export class CreditAccountUserController {
description: 'The list of credit account users.',
type: [ReadCreditAccountUserDto],
})
@IsFeatureFlagEnabled('CREDIT-ACCOUNT')
@Get()
@Roles(Role.READ_CREDIT_ACCOUNT)
async getCreditAccountUsers(
Expand Down
15 changes: 14 additions & 1 deletion vehicles/src/modules/credit-account/credit-account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export class CreditAccountService {
null,
null,
creditAccountUserMappedToCreditAccount.creditAccountUserId,
true,
);
return this.classMapper.mapAsync(
updatedCreditAccountUserInfo?.at(0),
Expand Down Expand Up @@ -513,6 +514,7 @@ export class CreditAccountService {
null,
null,
newCreditAccountUser.creditAccountUserId,
true,
);
return this.classMapper.mapAsync(
newCreditAccountUserInfo?.at(0),
Expand Down Expand Up @@ -731,6 +733,7 @@ export class CreditAccountService {
creditAccountHolderCompanyId?: Nullable<number>,
creditAccountId?: Nullable<number>,
creditAccountUserId?: Nullable<number>,
isActive?: Nullable<boolean>,
) {
// Initializing query builder for credit account user repository.
const creditAccountUserQB = this.creditAccountUserRepository
Expand Down Expand Up @@ -784,6 +787,13 @@ export class CreditAccountService {
);
}

// Adding condition to filter out disbled creditAccount Users.
if (isActive === true || isActive === false) {
creditAccountUserQB.andWhere('creditAccountUser.isActive = :isActive', {
isActive: isActive ? 'Y' : 'N',
});
}

// Executing the query and returning the results.
return await creditAccountUserQB.getMany();
}
Expand All @@ -804,6 +814,8 @@ export class CreditAccountService {
null,
creditAccountHolder,
creditAccountId,
null,
true,
);
}

Expand Down Expand Up @@ -834,7 +846,8 @@ export class CreditAccountService {

if (includeAccountHolder) {
const creditAccountHolderInfo =
creditAccountUsers?.at(0)?.creditAccount?.company;
await this.companyService.findOneEntity(creditAccountHolder);

const mappedCreditAccountHolderInfo = await this.classMapper.mapAsync(
creditAccountHolderInfo,
Company,
Expand Down

0 comments on commit cc657a8

Please sign in to comment.