Add API endpoint to retrieve a single shotpoint.

This will be used by the new event dialogue in the
frontend to get shotpoint information when creating
or editing events.
This commit is contained in:
D. Berge
2022-02-27 17:31:08 +01:00
parent d33fe4e936
commit 920ea83ece
9 changed files with 126 additions and 2 deletions

View File

@@ -119,6 +119,9 @@ app.map({
'/project/:project/sequence/:sequence': {
get: [ mw.sequence.get ],
patch: [ mw.auth.access.write, mw.sequence.patch ],
'/:point': {
get: [ mw.sequence.point.get ]
}
},
'/project/:project/plan/': {

View File

@@ -1,5 +1,7 @@
module.exports = {
list: require('./list'),
get: require('./get'),
patch: require('./patch')
patch: require('./patch'),
point: require('./point')
};

View File

@@ -0,0 +1,28 @@
const { sequence } = require('../../../../../lib/db');
module.exports = async function (req, res, next) {
try {
const feature = await sequence.point.get(req.params.project, req.params.sequence, req.params.point, req.query);
if (feature) {
const geojson = {
type: "Feature",
geometry: feature.geometry,
properties: {...feature}
};
delete geojson.properties.geometry;
res.status(200).send(geojson);
} else {
res.status(404).send();
}
next();
} catch (err) {
next(err);
}
};

View File

@@ -0,0 +1,23 @@
const json = require('./json');
const geojson = require('./geojson');
module.exports = async function (req, res, next) {
try {
const handlers = {
"application/json": json,
"application/geo+json": geojson,
};
const mimetype = (handlers[req.query.mime] && req.query.mime) || req.accepts(Object.keys(handlers));
if (mimetype) {
res.set("Content-Type", mimetype);
await handlers[mimetype](req, res, next);
} else {
res.status(406).send();
next();
}
} catch (err) {
next(err);
}
}

View File

@@ -0,0 +1,20 @@
const { sequence } = require('../../../../../lib/db');
module.exports = async function (req, res, next) {
try {
const feature = await sequence.point.get(req.params.project, req.params.sequence, req.params.point, req.query)
if (feature) {
res.status(200).send(feature);
} else {
res.status(404).send();
}
next();
} catch (err) {
next(err);
}
};

View File

@@ -0,0 +1,3 @@
module.exports = {
get: require('./get')
};

View File

@@ -5,5 +5,7 @@ module.exports = {
post: require('./post'),
put: require('./put'),
patch: require('./patch'),
delete: require('./delete')
delete: require('./delete'),
point: require('./point')
}

View File

@@ -0,0 +1,34 @@
const { setSurvey } = require('../../connection');
const { project } = require('../../utils');
async function get (projectId, sequence, point, opts = {}) {
const client = await setSurvey(projectId);
async function query (table='raw_shots') {
const text = `
SELECT
sequence, line, point, objref, tstamp, hash, ST_Transform(geometry, 4326)::json as geometry, meta
FROM ${table}
WHERE sequence = $1 and point = $2;
`;
const values = [sequence, point];
const res = await client.query(text, values);
return res.rows;
}
let res;
if (opts.kind=="final") {
res = project(await query("final_shots"), opts.project);
} else {
res = project(await query("raw_shots"), opts.project);
}
client.release();
return res[0];
}
module.exports = get;

View File

@@ -0,0 +1,9 @@
module.exports = {
// list: require('./list'),
get: require('./get'),
// post: require('./post'),
// put: require('./put'),
// patch: require('./patch'),
// delete: require('./delete')
}