diff --git a/src/device-registry/config/global/mappings.js b/src/device-registry/config/global/mappings.js index 0147420a4a..73a9b909f6 100644 --- a/src/device-registry/config/global/mappings.js +++ b/src/device-registry/config/global/mappings.js @@ -27,12 +27,12 @@ function generateDateFormatWithoutHrs(ISODate) { const mappings = { AQI_INDEX: { - good: [0, 12], - moderate: [12.1, 35.4], - u4sg: [35.5, 55.4], - unhealthy: [55.5, 150.4], - very_unhealthy: [150.5, 250.4], - hazardous: [250.5, 500], + good: { min: 0, max: 9.0 }, + moderate: { min: 9.1, max: 35.4 }, + u4sg: { min: 35.5, max: 55.4 }, + unhealthy: { min: 55.5, max: 125.4 }, + very_unhealthy: { min: 125.5, max: 225.4 }, + hazardous: { min: 225.5, max: null }, }, GET_ROAD_METADATA_PATHS: { altitude: "altitude", diff --git a/src/device-registry/utils/generate-filter.js b/src/device-registry/utils/generate-filter.js index 1529041481..c4ee0b31de 100644 --- a/src/device-registry/utils/generate-filter.js +++ b/src/device-registry/utils/generate-filter.js @@ -80,8 +80,12 @@ const generateFilter = { if (!index) { delete filter["values.pm2_5.value"]; } else if (Object.keys(constants.AQI_INDEX).includes(index)) { - filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0]; - filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1]; + const range = constants.AQI_INDEX[index]; + filter["values.pm2_5.value"]["$gte"] = range.min; + // Only set $lte if max is not null + if (range.max !== null) { + filter["values.pm2_5.value"]["$lte"] = range.max; + } filter["index"] = index; } else { delete filter["values.pm2_5.value"]; @@ -341,8 +345,13 @@ const generateFilter = { if (!index) { delete filter["values.pm2_5.value"]; } else if (Object.keys(constants.AQI_INDEX).includes(index)) { - filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0]; - filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1]; + const range = constants.AQI_INDEX[index]; + filter["values.pm2_5.value"] = {}; + filter["values.pm2_5.value"]["$gte"] = range.min; + // Only set $lte if max is not null + if (range.max !== null) { + filter["values.pm2_5.value"]["$lte"] = range.max; + } filter["index"] = index; } else { delete filter["values.pm2_5.value"]; @@ -670,8 +679,13 @@ const generateFilter = { if (!index) { delete filter["values.pm2_5.value"]; } else if (Object.keys(constants.AQI_INDEX).includes(index)) { - filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0]; - filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1]; + const range = constants.AQI_INDEX[index]; + filter["values.pm2_5.value"] = {}; + filter["values.pm2_5.value"]["$gte"] = range.min; + // Only set $lte if max is not null + if (range.max !== null) { + filter["values.pm2_5.value"]["$lte"] = range.max; + } filter["index"] = index; } else { delete filter["values.pm2_5.value"];