Add war delete endpoint
parent
83f06e5914
commit
d5d4abd1a8
|
@ -64,7 +64,7 @@ wars.route('/')
|
|||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
//TODO: combine run and clean in one script
|
||||
//TODO: combine run and clean in one script, so log file gets touched only once
|
||||
exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + item._id, (error, stdout) => {
|
||||
if (error) {
|
||||
return next(error);
|
||||
|
@ -127,6 +127,26 @@ wars.route('/:id')
|
|||
});
|
||||
})
|
||||
|
||||
.delete(apiAuthenticationMiddleware, checkMT,(req, res, next) => {
|
||||
WarModel.findByIdAndRemove(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.wrongrequest;
|
||||
}
|
||||
else if (!item) {
|
||||
err = new Error("item not found");
|
||||
err.status = codes.notfound;
|
||||
}
|
||||
|
||||
// delete players with this war ID as foreign key
|
||||
PlayerModel.find({warId: item._id}).remove().exec();
|
||||
|
||||
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler user.use(..)
|
||||
res.locals.processed = true;
|
||||
next(err); // this works because err is in normal case undefined and that is the same as no parameter
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
.all(
|
||||
routerHandling.httpMethodNotAllowed
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "opt-cc",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue