Skip to content

Commit

Permalink
fix(ttc): add tree cover density validation to getWHEREQuery method
Browse files Browse the repository at this point in the history
Now when the user select a thresold on the ttc layer, tree cover density widget will ignore that and keep fetching using >=10% of thresold
and the right table wri_tropical_tree_cover__decile
  • Loading branch information
willian-viana committed Oct 16, 2023
1 parent 528212e commit 601c39a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions services/analysis-cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ const SQL_QUERIES = {

const ALLOWED_PARAMS = {
annual: ['adm0', 'adm1', 'adm2', 'threshold', 'forestType', 'landCategory'],
treeCoverDensity: [
'adm0',
'adm1',
'adm2',
'threshold',
'forestType',
'landCategory',
],
integrated_alerts: [
'adm0',
'adm1',
Expand Down Expand Up @@ -340,6 +348,8 @@ export const getWHEREQuery = (params) => {
(!isNaN(value) && !['adm0', 'confidence'].includes(p))
);

const isTreeCoverDensity = dataset === 'treeCoverDensity';

let paramKey = p;
if (p === 'confidence') paramKey = 'confidence__cat';
if (p === 'threshold') {
Expand Down Expand Up @@ -386,12 +396,12 @@ export const getWHEREQuery = (params) => {
}`
: ''
}${
!isPolyname
? `${paramKey}${comparisonString}${
!isPolyname && isTreeCoverDensity && p === 'threshold'
? ''
: `${paramKey}${comparisonString}${
isNumericValue ? value : `'${value}'`
}`
: ''
}${isLast ? '' : ' AND '}`;
}${isLast || isTreeCoverDensity ? '' : ' AND '}`;

paramString = paramString.concat(polynameString);
});
Expand Down Expand Up @@ -2065,7 +2075,10 @@ export const getTreeCoverDensity = (params) => {
getLocationSelect({ ...params, cast: false })
)
.replace(/{location}/g, getLocationSelect({ ...params }))
.replace('{WHERE}', getWHEREQuery({ ...params, dataset: 'annual' }))
.replace(
'{WHERE}',
getWHEREQuery({ ...params, dataset: 'treeCoverDensity' })
)
);

return dataRequest.get(url).then((response) => response.data);
Expand Down

0 comments on commit 601c39a

Please sign in to comment.