Skip to content

Commit ec300e3

Browse files
committed
fixing lith_att parameters
1 parent 94d73fb commit ec300e3

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

v2/units.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ module.exports = function (req, res, next, cb) {
275275
function (data, callback) {
276276
var where = "",
277277
limit = "sample" in req.query ? (cb ? " LIMIT 15 " : " LIMIT 5") : "",
278-
orderby = [],
279-
params = {};
278+
orderby = [];
280279

281280
larkin.trace(data);
282281

@@ -333,40 +332,32 @@ module.exports = function (req, res, next, cb) {
333332

334333
where += lithWhere.join(" OR ") + ")";
335334
}
335+
if (req.query.lith_att_id || req.query.lith_att || req.query.lith_att_type) {
336+
let lithAttField;
336337

337-
if (
338-
req.query.lith_att_id ||
339-
req.query.lith_att ||
340-
req.query.lith_att_type
341-
) {
342-
where += `
343-
AND units.id = ANY(
344-
SELECT unit_liths.unit_id
345-
FROM macrostrat.unit_liths
346-
JOIN macrostrat.liths ON lith_id = liths.id
347-
JOIN macrostrat.unit_liths_atts ON unit_liths_atts.unit_lith_id = unit_liths.id
348-
JOIN macrostrat.lith_atts ON unit_liths_atts.lith_att_id = lith_atts.id
349-
WHERE :lith_att_field`;
350-
//why is the syntax lith_att)) ?
351338
if (req.query.lith_att_id) {
352-
where += " = ANY(:lith_att)) ";
353-
params["lith_att_field"] = "unit_liths_atts.lith_att_id";
339+
lithAttField = "unit_liths_atts.lith_att_id";
354340
params["lith_att"] = larkin.parseMultipleIds(req.query.lith_att_id);
355341
} else if (req.query.lith_att) {
356-
where += " = ANY(:lith_att)) ";
357-
params["lith_att_field"] = "lith_atts.lith_att";
358-
params["lith_att"] = larkin.parseMultipleStrings(
359-
req.query.lith_att,
360-
);
342+
lithAttField = "lith_atts.lith_att";
343+
params["lith_att"] = larkin.parseMultipleStrings(req.query.lith_att);
361344
} else if (req.query.lith_att_type) {
362-
where += " = ANY(:lith_att)) ";
363-
params["lith_att_field"] = "lith_atts.att_type";
364-
params["lith_att"] = larkin.parseMultipleStrings(
365-
req.query.lith_att_type,
366-
);
345+
lithAttField = "lith_atts.att_type";
346+
params["lith_att"] = larkin.parseMultipleStrings(req.query.lith_att_type);
367347
}
348+
349+
where += `
350+
AND units.id = ANY(
351+
SELECT unit_liths.unit_id
352+
FROM macrostrat.unit_liths
353+
JOIN macrostrat.liths ON lith_id = liths.id
354+
JOIN macrostrat.unit_liths_atts ON unit_liths_atts.unit_lith_id = unit_liths.id
355+
JOIN macrostrat.lith_atts ON unit_liths_atts.lith_att_id = lith_atts.id
356+
WHERE ${lithAttField} = ANY(:lith_att)
357+
)`;
368358
}
369359

360+
370361
if (data.age_bottom !== 99999) {
371362
where += " AND b_age > :age_top AND t_age < :age_bottom";
372363
params["age_top"] = data.age_top;

0 commit comments

Comments
 (0)