Skip to content

Commit

Permalink
fix(viirs): validating the new option from the VIIRS layer to avoid e…
Browse files Browse the repository at this point in the history
…rrors on the query
  • Loading branch information
willian-viana committed Nov 7, 2023
1 parent a67b6ff commit 4387ac4
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions services/get-where-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,23 @@ export const getWHEREQuery = (params = {}) => {
}

/*
* Removing confidence_cat = 'false' from VIIRS request
* Removing confidence_cat = 'all' from VIIRS request
* if the user selects 'all alerts' on the VIIRS layer,
* we don't want to add a new parameter to the query
*/
if (isVIIRS) {
if (
typeof params?.confidence === 'boolean' &&
params?.confidence === false
) {
paramKeys = paramKeys.filter((item) => item !== 'confidence');
}

if (params?.confidence === 'false' || params?.confidence === 'true') {
paramKeys = paramKeys.filter((item) => item !== 'confidence');
}
if (isVIIRS && params?.confidence === 'all') {
paramKeys = paramKeys.filter((item) => item !== 'confidence');
}

paramKeys.forEach((parameter, index) => {
const isLastParameter = paramKeys.length - 1 === index;
const hasFilterOption = ['forestType', 'landCategory'].includes(parameter);
let value = hasFilterOption ? 1 : params[parameter];
const value = hasFilterOption ? 1 : params[parameter];
const filterOption = allFilterOptions.find(
(pname) => pname.value === params[parameter]
);

/*
* when the user selects high confidence on VIIRS Layer
* the confidence option returns a string 'true'
* the right value should be 'h'
* Until we fix this return, we need to validate the parameter
*/
if (isVIIRS && parameter === 'confidence') {
if (
typeof params?.confidence === 'boolean' &&
params?.confidence === true
) {
value = 'h';
}
}

const tableKey =
filterOption &&
(filterOption.tableKey || filterOption.tableKeys[dataset || 'annual']);
Expand Down

0 comments on commit 4387ac4

Please sign in to comment.