From 0aa1020299f29a41c7a7557710dd37d08b8aae5c Mon Sep 17 00:00:00 2001 From: Tariq Soliman Date: Thu, 16 Jan 2025 14:55:06 -0800 Subject: [PATCH] Fix endtime only geodataset time queries --- API/Backend/Geodatasets/routes/geodatasets.js | 51 +++++++++++-------- src/essence/Basics/Layers_/LayerCapturer.js | 17 +++++-- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/API/Backend/Geodatasets/routes/geodatasets.js b/API/Backend/Geodatasets/routes/geodatasets.js index 8a2bfe41..5a5f1490 100644 --- a/API/Backend/Geodatasets/routes/geodatasets.js +++ b/API/Backend/Geodatasets/routes/geodatasets.js @@ -77,7 +77,9 @@ function get(reqtype, req, res, next) { )}, ${Utils.forceAlphaNumUnder(parseFloat(maxy))}, 4326), geom)`; hasBounds = true; } + let startProp = "start_time"; let start_time = ""; + let endProp = "end_time"; let end_time = ""; if (req.query?.endtime != null) { const format = req.query?.format || "YYYY-MM-DDTHH:MI:SSZ"; @@ -86,10 +88,6 @@ function get(reqtype, req, res, next) { else t += `AND `; if ( - req.query?.startProp == null || - req.query?.startProp.indexOf(`'`) != -1 || - req.query?.endProp == null || - req.query?.endProp.indexOf(`'`) != -1 || req.query?.starttime == null || req.query?.starttime.indexOf(`'`) != -1 || req.query?.endtime == null || @@ -98,37 +96,46 @@ function get(reqtype, req, res, next) { ) { res.send({ status: "failure", - message: "Missing inner or malformed 'time' parameters.", + message: "Missing inner or malformed time parameters.", }); return; } - start_time = new Date(req.query.starttime).getTime(); + start_time = new Date( + req.query.starttime || "1970-01-01T00:00:00Z" + ).getTime(); end_time = new Date(req.query.endtime).getTime(); - const startProp = Utils.forceAlphaNumUnder(req.query.startProp); - const endProp = Utils.forceAlphaNumUnder(req.query.endProp); + startProp = Utils.forceAlphaNumUnder( + req.query.startProp || startProp + ); + endProp = Utils.forceAlphaNumUnder(req.query.endProp || endProp); // prettier-ignore t += [ - `(`, - `${startProp} IS NOT NULL AND ${endProp} IS NOT NULL AND`, - ` ${startProp} >= ${start_time}`, - ` AND ${endProp} <= ${end_time}`, - `)`, - ` OR `, - `(`, - `${startProp} IS NULL AND ${endProp} IS NOT NULL AND`, - ` ${endProp} >= ${start_time}`, - ` AND ${endProp} >= ${end_time}`, - `)` - ].join('') + `(`, + `${startProp} IS NOT NULL AND ${endProp} IS NOT NULL AND`, + ` ${startProp} >= ${start_time}`, + ` AND ${endProp} <= ${end_time}`, + `)`, + ` OR `, + `(`, + `${startProp} IS NULL AND ${endProp} IS NOT NULL AND`, + ` ${endProp} >= ${start_time}`, + ` AND ${endProp} <= ${end_time}`, + `)` + ].join('') q += t; } q += `;`; - + console.log(q); sequelize .query(q, { - replacements: {}, + replacements: { + startProp: startProp, + start_time: start_time, + endProp: endProp, + end_time: end_time, + }, }) .then(([results]) => { let geojson = { type: "FeatureCollection", features: [] }; diff --git a/src/essence/Basics/Layers_/LayerCapturer.js b/src/essence/Basics/Layers_/LayerCapturer.js index 76a89a65..36a9ea78 100644 --- a/src/essence/Basics/Layers_/LayerCapturer.js +++ b/src/essence/Basics/Layers_/LayerCapturer.js @@ -145,6 +145,9 @@ export const captureVector = (layerObj, options, cb, dynamicCb) => { layerData?.variables ?.dynamicExtentMoveThreshold == null || + layerData?.variables + ?.dynamicExtentMoveThreshold === + '' || layerData._ignoreDynamicExtentMoveThreshold === true || F_.lngLatDistBetween( @@ -358,12 +361,18 @@ export const captureVector = (layerObj, options, cb, dynamicCb) => { } else { switch (urlSplit[0]) { case 'geodatasets': + const body = { + layer: urlSplitRaw[1], + type: 'geojson', + } + if (layerData.time?.enabled === true) { + body.starttime = layerData.time.start + body.endtime = layerData.time.end + } + calls.api( 'geodatasets_get', - { - layer: urlSplitRaw[1], - type: 'geojson', - }, + body, (data) => { cb(data) },