Implement GET middleware for events.

Produces a choice of outputs: JSON, GeoJSON, Seis+JSON and HTML.
This commit is contained in:
D. Berge
2021-05-11 23:12:42 +02:00
parent 95647337aa
commit d9f4583224
6 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
const { event, sequence, configuration } = require('../../../../lib/db');
const { transform } = require('../../../../lib/sse');
const render = require('../../../../lib/render');
const html = async function (req, res, next) {
try {
const query = req.query;
query.sequence = req.params.sequence;
const events = await event.list(req.params.project, query);
const sequences = await sequence.list(req.params.project, query);
const seis = transform(events, sequences, {projectId: req.params.project});
const templates = await configuration.get(req.params.project, "sse/templates");
const template = templates[0].template;
const response = await render(seis, template);
res.status(200).send(response);
next();
} catch (err) {
next(err);
}
};
module.exports = html;