Implement event DELETE middleware

This commit is contained in:
D. Berge
2020-08-22 20:28:50 +02:00
parent 5349708fb8
commit 0c4d91c603

View File

@@ -0,0 +1,34 @@
const { event } = require('../../../lib/db');
module.exports = async function (req, res, next) {
try {
const payload = Object.assign({}, req.body);
if (req.params.type && req.params.id) {
payload.type = req.params.type;
payload.id = req.params.id;
}
if (req.params.labels) {
payload.labels = req.params.labels.split(";");
}
if (!req.meta.isLabel) {
// User is requesting that we delete the whole event,
// not just labels
// FIXME NOTE Removal of labels would be best done via
// a PUT request.
delete payload.labels
}
await event.del(req.params.project, payload, req.query);
res.status(204).send();
next();
} catch (err) {
console.error(err);
next(err);
}
};