Skip to content

Commit

Permalink
Fix: ORV2-1986 Company name search will search both legal and altern…
Browse files Browse the repository at this point in the history
…ate name (#1208)
  • Loading branch information
praju-aot authored Feb 15, 2024
1 parent f3bc536 commit 2567f39
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frontend/src/features/idir/search/api/idirSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getCompanyDataBySearch = (
): Promise<PaginatedResponse<CompanyProfile>> => {
const searchURL = new URL(`${VEHICLES_URL}/${searchEntity}`);
if (searchByFilter === "companyName") {
searchURL.searchParams.set("legalName", searchString);
searchURL.searchParams.set("companyName", searchString);
} else {
searchURL.searchParams.set("clientNumber", searchString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CompanyController {
page: getCompanyQueryParamsDto.page,
take: getCompanyQueryParamsDto.take,
orderBy: getCompanyQueryParamsDto.orderBy,
legalName: getCompanyQueryParamsDto.legalName,
companyName: getCompanyQueryParamsDto.companyName,
clientNumber: getCompanyQueryParamsDto.clientNumber,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class CompanyService {
page: number;
take: number;
orderBy?: string;
legalName?: string;
companyName?: string;
clientNumber?: string;
}): Promise<PaginationDto<ReadCompanyDto>> {
const companiesQB = this.companyRepository
Expand All @@ -402,11 +402,17 @@ export class CompanyService {
// Apply mandatory condition to ensure at least one filter is applied
companiesQB.where('company.companyId IS NOT NULL');

if (findCompanyPaginatedOptions.legalName) {
// Add condition for filtering by legal name if provided
companiesQB.andWhere('company.legalName LIKE :legalName', {
legalName: `%${findCompanyPaginatedOptions.legalName}%`,
});
if (findCompanyPaginatedOptions.companyName) {
// Add condition for filtering by legal name or alternate name if provided
companiesQB.andWhere(
new Brackets((qb) => {
qb.where('company.legalName LIKE :legalName', {
legalName: `%${findCompanyPaginatedOptions.companyName}%`,
}).orWhere('company.alternateName LIKE :legalName', {
legalName: `%${findCompanyPaginatedOptions.companyName}%`,
});
}),
);
}

if (findCompanyPaginatedOptions.clientNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export class GetCompanyQueryParamsDto extends PageOptionsDto {
@ApiProperty({
example: 'Parisian LLC Trucking',
description:
'Filters the results with the legal name of the company. This field is optional.',
'Filters the results with the legal/DBA name of the company. This field is optional.',
required: false,
})
@IsOptional()
@IsString()
legalName?: string;
companyName?: string;

@ApiProperty({
example: 'B3-000005-722',
Expand Down
2 changes: 1 addition & 1 deletion vehicles/test/unit/company/company.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('CompanyController', () => {
take: 10,
orderBy: 'companyId:DESC',
clientNumber: 'Red Truck Inc',
legalName: 'B3-000005-722',
companyName: 'B3-000005-722',
};
const retCompanyData = await controller.getCompanyPaginated(
request,
Expand Down
4 changes: 2 additions & 2 deletions vehicles/test/unit/company/company.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ describe('CompanyService', () => {
take: 10,
orderBy: 'companyId:DESC',
clientNumber: 'Red Truck Inc',
legalName: 'B3-000005-722',
companyName: 'B3-000005-722',
};

const retCompanies = await service.findCompanyPaginated({
page: getCompanyQueryParamsDto.page,
take: getCompanyQueryParamsDto.take,
orderBy: getCompanyQueryParamsDto.orderBy,
legalName: getCompanyQueryParamsDto.legalName,
companyName: getCompanyQueryParamsDto.companyName,
clientNumber: getCompanyQueryParamsDto.clientNumber,
});

Expand Down

0 comments on commit 2567f39

Please sign in to comment.