Skip to content

Commit

Permalink
fix for partial post code text search
Browse files Browse the repository at this point in the history
  • Loading branch information
RiteshHMCTS committed Nov 30, 2022
1 parent 2bcdb41 commit e31e9aa
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions api/organisation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ function filterOrganisations(orgs: any, searchFilter: string): any[] {
return orgs.filter((org: any) => {
if (org) {
for (const field of TEXT_FIELDS_TO_CHECK) {
if (field === 'postCode') {
if (postCodeMatches(org, searchFilter)) {
return true;
}
if (field === 'postCode' && postCodeMatches(org, searchFilter)) {
return true;
} else if (textFieldMatches(org, field, searchFilter)) {
return true;
}
Expand All @@ -204,11 +202,8 @@ function filterOrganisations(orgs: any, searchFilter: string): any[] {

function postCodeMatches(org: any, filter: string): boolean {
return org['contactInformation'].map(({postCode}) => {
if(!postCode) {
return;
}
return postCode.split(' ').join('').toLowerCase()
}).includes(filter.split(' ').join(''));
return postCode && postCode.split(' ').join('').toLowerCase()
}).some(element => element && element.indexOf(filter.split(' ').join('')) >= 0);
}

function createPaginatedResponse(paginationParameters: any, filteredOrganisations: any) {
Expand Down

0 comments on commit e31e9aa

Please sign in to comment.