From 65b58ec246adb00194b5028742726e93ab05817c Mon Sep 17 00:00:00 2001 From: Amy Fromandi Date: Wed, 30 Oct 2024 10:36:08 -0500 Subject: [PATCH] polishing up the last endpoints --- api-tests/app.ts | 3 +-- v2/definitions/strat_names.ts | 2 +- v2/geologic_units_burwell.ts | 1 - v2/geologic_units_gmna.ts | 11 ++++++++--- v2/geologic_units_gmus.ts | 10 ++++++++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api-tests/app.ts b/api-tests/app.ts index f37fb8f1..f369fee1 100644 --- a/api-tests/app.ts +++ b/api-tests/app.ts @@ -10,8 +10,7 @@ import * as path from 'path'; const testFiles = [ // waiting for confirmation to implement solution for 'defs_sources.ts', - 'geologic_units_burwell.ts', - //'geologic_units_gmna.ts', + 'geologic_units_gmna.ts', //'geologic_units_gmus.ts' //'mancos_test_cases.ts', //'mobile_macro_summary.ts', diff --git a/v2/definitions/strat_names.ts b/v2/definitions/strat_names.ts index 02973295..2a03d546 100644 --- a/v2/definitions/strat_names.ts +++ b/v2/definitions/strat_names.ts @@ -19,7 +19,7 @@ module.exports = function (req, res, next, cb) { params["strat_name"] = req.query.strat_name; } else if (req.query.strat_name_id) { where.push( - "parent IN (:strat_name_id) OR l.strat_name_id = ANY(:strat_name_id)", + "parent = ANY(:strat_name_id) OR l.strat_name_id = ANY(:strat_name_id)", ); params["strat_name_id"] = larkin.parseMultipleIds( req.query.strat_name_id, diff --git a/v2/geologic_units_burwell.ts b/v2/geologic_units_burwell.ts index 31249191..3ddab8a3 100644 --- a/v2/geologic_units_burwell.ts +++ b/v2/geologic_units_burwell.ts @@ -181,7 +181,6 @@ module.exports = function (req, res, next, cb) { where = ""; } - console.log(req.query.scale) if (req.query.scale) { var requestedScales = larkin.parseMultipleStrings(req.query.scale); var scales = requestedScales.filter(function (d) { diff --git a/v2/geologic_units_gmna.ts b/v2/geologic_units_gmna.ts index 12505d88..2c20b5e7 100644 --- a/v2/geologic_units_gmna.ts +++ b/v2/geologic_units_gmna.ts @@ -16,9 +16,14 @@ module.exports = function (req, res, next) { var where = [], params = [], - limit = "sample" in req.query ? " LIMIT 5" : "", geomField = geo ? ", ST_AsGeoJSON(geom) AS geometry" : "", + limit, from = ""; + if (req.query.sample === "") { + limit = " LIMIT 5"; + } else { + limit = ""; + } if (req.query.gid && req.query.gid != "undefined") { where.push(" gid = $" + (where.length + 1)); @@ -72,14 +77,14 @@ module.exports = function (req, res, next) { : ""; } - if (where.length < 1 && !("sample" in req.query)) { + if (where.length < 1 && !(req.query.sample)) { return larkin.error(req, res, next, "Invalid params"); } if (where.length > 0) { where = " WHERE " + where.join(", "); } - + //todo modify query to use macrostrat schema. larkin.queryPg( "geomacro", "SELECT gid, unit_abbre, COALESCE(rocktype, '') AS rocktype, COALESCE(lithology, '') AS lith, lith_type, lith_class, min_interval AS t_interval, min_age::float AS t_age, max_interval AS b_interval, max_age::float AS b_age, containing_interval, interval_color AS color" + diff --git a/v2/geologic_units_gmus.ts b/v2/geologic_units_gmus.ts index ac7c6fce..8dec2189 100644 --- a/v2/geologic_units_gmus.ts +++ b/v2/geologic_units_gmus.ts @@ -18,12 +18,18 @@ module.exports = function (req, res, next) { var where = [], params = [], - limit = "sample" in req.query ? " LIMIT 5" : "", + limit, from = "gmus.lookup_units lu JOIN gmus.ages a ON lu.unit_link = a.unit_link LEFT JOIN gmus.liths l ON lu.unit_link = l.unit_link LEFT JOIN gmus.best_geounits_macrounits gm ON lu.gid = gm.geologic_unit_gid", geomQuery = geo ? ", ST_AsGeoJSON(geom) AS geometry" : "", orderBy = ""; + if (req.query.sample === "") { + limit = " LIMIT 5"; + } else { + limit = ""; + } + async.parallel( [ function (callback) { @@ -194,7 +200,7 @@ module.exports = function (req, res, next) { }, ], function () { - if (where.length < 1 && !("sample" in req.query)) { + if (where.length < 1 && !(req.query.sample)) { return larkin.error(req, res, next, "Invalid params"); }