API: Add label querying endpoint.

Labels can be associated with events and can have
display properties such as a description and colour,
this is why we need an endpoint for the client to
retrieve them.
This commit is contained in:
D. Berge
2020-08-12 11:41:28 +02:00
parent d52f8f8bc2
commit a73376572b
15 changed files with 48 additions and 1 deletions

View File

@@ -90,6 +90,10 @@ app.map({
// get: [ mw.event.get ],
// put: [ mw.event.put ],
// },
'/project/:project/label/': {
get: [ mw.label.list ],
// post: [ mw.label.post ],
},
//
// '/project/:id/permissions/:mode(read|write)?': {
// get: [ mw.permissions.get ],

View File

@@ -5,5 +5,6 @@ module.exports = {
sequence: require('./sequence'),
user: require('./user'),
auth: require('./auth'),
gis: require('./gis')
gis: require('./gis'),
label: require('./label')
};

View File

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

View File

@@ -0,0 +1,9 @@
const { label } = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await label.list(req.params.project, req.query));
next();
};

View File

@@ -5,4 +5,5 @@ module.exports = {
sequence: require('./sequence'),
event: require('./event'),
gis: require('./gis'),
label: require('./label')
};

View File

View File

View File

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

View File

@@ -0,0 +1,16 @@
const { pool } = require('../connection');
async function list (projectId, opts = {}) {
await pool.query("CALL set_survey($1);", [projectId]);
const text = `
SELECT *
FROM labels
ORDER BY name;
`;
const res = await pool.query(text);
return res.rows;
}
module.exports = list;

View File

View File