Add API endpoint for creating a project

This commit is contained in:
D. Berge
2023-08-23 19:20:07 +02:00
parent 6033b45ed3
commit 1a6500308f
3 changed files with 18 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ app.use(mw.auth.authentify);
app.map({
'/project': {
get: [ mw.project.get ], // Get list of projects
post: [ mw.auth.access.admin, mw.project.post ], // Create a new project
},
'/project/:project': {
get: [ mw.project.summary.get ], // Get project data

View File

@@ -1,4 +1,5 @@
module.exports = {
get: require('./get'),
post: require('./post'),
summary: require('./summary'),
};

View File

@@ -0,0 +1,16 @@
const { project } = require('../../../lib/db');
module.exports = async function (req, res, next) {
try {
const payload = req.body;
const projectDefinition = await project.post(payload);
res.status(201).send(projectDefinition);
next();
} catch (err) {
next(err);
}
};