From 601c39a756491192e30571e49eedd2214ce3736e Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Mon, 16 Oct 2023 18:05:57 -0300 Subject: [PATCH] fix(ttc): add tree cover density validation to getWHEREQuery method 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 --- services/analysis-cached.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/services/analysis-cached.js b/services/analysis-cached.js index 299ee31820..cbec3a054d 100644 --- a/services/analysis-cached.js +++ b/services/analysis-cached.js @@ -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', @@ -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') { @@ -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); }); @@ -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);