Skip to content

Commit ef207d6

Browse files
committed
fix: adapts /map/plant-location API query to consider single-tree-registrations
- also excludes deleted interventions from results - restricts results to single and multi tree registrations
1 parent 7227467 commit ef207d6

File tree

1 file changed

+15
-7
lines changed
  • pages/api/data-explorer/map/plant-location

1 file changed

+15
-7
lines changed

pages/api/data-explorer/map/plant-location/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ handler.post(async (req, response) => {
1919
req.body;
2020

2121
try {
22-
let query =
23-
'SELECT iv.guid, iv.trees_planted as treeCount, iv.geometry, COALESCE(ss.name, ps.other_species, iv.other_species) AS name \
24-
FROM planted_species ps \
25-
INNER JOIN intervention iv ON ps.intervention_id = iv.id \
26-
LEFT JOIN scientific_species ss ON ps.scientific_species_id = ss.id \
27-
JOIN project pp ON iv.plant_project_id = pp.id \
28-
WHERE pp.guid = ?';
22+
let query = `
23+
SELECT
24+
iv.guid,
25+
iv.trees_planted as treeCount,
26+
iv.geometry,
27+
COALESCE(ss.name, ps.other_species, iv.other_species, 'Unknown') AS name
28+
FROM intervention iv
29+
LEFT JOIN planted_species ps ON iv.id = ps.intervention_id
30+
LEFT JOIN scientific_species ss ON COALESCE(iv.scientific_species_id, ps.scientific_species_id) = ss.id
31+
JOIN project pp ON iv.plant_project_id = pp.id
32+
WHERE
33+
pp.guid = ? AND
34+
iv.deleted_at IS NULL AND
35+
iv.type in ('multi-tree-registration', 'single-tree-registration')
36+
`;
2937

3038
const values = [projectId];
3139

0 commit comments

Comments
 (0)