diff --git a/src/apps/companies/constants.js b/src/apps/companies/constants.js index ed1f0709a91..9c8a86d8e77 100644 --- a/src/apps/companies/constants.js +++ b/src/apps/companies/constants.js @@ -5,6 +5,7 @@ const QUERY_FIELDS_MAP = { archived: 'archived', name: 'name', sectorDescends: 'sector_descends', + subSectorDescends: 'sub_sector_descends', country: 'country', ukRegion: 'uk_region', headquarterType: 'headquarter_type', diff --git a/src/modules/search/services.js b/src/modules/search/services.js index da16eff766b..0ef1d97cf2e 100644 --- a/src/modules/search/services.js +++ b/src/modules/search/services.js @@ -26,6 +26,19 @@ const buildOptions = (isAggregation, searchUrl, body, entity) => { } } +const mergeSectorAndSubSectorParams = (requestBody) => { + const { sub_sector_descends, sector_descends, ...reqBody } = requestBody + const mergedSectors = [ + ...(sector_descends ? sector_descends : []), + ...(sub_sector_descends ? sub_sector_descends : []), + ] + + return { + ...reqBody, + sector_descends: mergedSectors, + } +} + function search({ req, searchTerm: term = '', @@ -68,7 +81,7 @@ function exportSearch({ req, searchTerm = '', searchEntity, requestBody }) { if (searchEntity == 'investment_project') { transformedRequestBody = transformLandDateFilters(requestBody) } else { - transformedRequestBody = requestBody + transformedRequestBody = mergeSectorAndSubSectorParams(requestBody) } const searchUrl = `${config.apiRoot}/${apiVersion}/search` // If the requested CSV export should contain policy feedback, we need to call @@ -125,4 +138,5 @@ module.exports = { exportSearch, searchAutocomplete, searchDnbCompanies, + mergeSectorAndSubSectorParams, }