Add war delete endpoint

pull/1/head
Florian Hartwich 2017-07-09 11:32:20 +02:00
parent 83f06e5914
commit d5d4abd1a8
2 changed files with 22 additions and 2 deletions

View File

@ -64,7 +64,7 @@ wars.route('/')
if (err) { if (err) {
return next(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) => { exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + item._id, (error, stdout) => {
if (error) { if (error) {
return next(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( .all(
routerHandling.httpMethodNotAllowed routerHandling.httpMethodNotAllowed
); );

View File

@ -1,6 +1,6 @@
{ {
"name": "opt-cc", "name": "opt-cc",
"version": "1.0.0", "version": "1.1.0",
"license": "MIT", "license": "MIT",
"private": true, "private": true,
"scripts": { "scripts": {