Fix delete endpoint - remove associated wars

pull/9/head
Florian Hartwich 2017-09-14 12:01:16 +02:00
parent dbca2a3d93
commit 947e8df1f7
3 changed files with 10 additions and 3 deletions

View File

@ -13,6 +13,8 @@ const checkMT = require('../middleware/permission-check').checkMT;
// Mongoose Model using mongoDB
const CampaignModel = require('../models/campaign');
const WarModel = require('../models/war');
const campaigns = express.Router();
@ -66,7 +68,10 @@ campaigns.route('/:id')
err.status = codes.notfound;
return next(err);
}
return next();
WarModel.find({campaign: req.params.id}).remove().exec();
res.locals.processed = true;
next();
})
})

View File

@ -49,7 +49,7 @@
id="campaign"
[(ngModel)]="war.campaign"
required>
<option *ngFor="let campaign of warService.campaigns" [ngValue]="campaign._id">
<option *ngFor="let campaign of campaignService.campaigns" [ngValue]="campaign._id">
{{campaign.title}}
</option>
</select>

View File

@ -3,6 +3,7 @@ import {ActivatedRoute, Router} from "@angular/router";
import {NgForm} from "@angular/forms";
import {WarService} from "../../services/war-service/war.service";
import {War} from "../../models/model-interfaces";
import {CampaignService} from "../../services/campaign-service/campaign.service";
@Component({
@ -28,7 +29,8 @@ export class WarSubmitComponent {
constructor(private route: ActivatedRoute,
private router: Router,
private warService: WarService) {
private warService: WarService,
private campaignService: CampaignService) {
}
fileChange(event) {