Skip to content

Instantly share code, notes, and snippets.

@johndavidback
Last active December 14, 2015 02:48
Show Gist options
  • Save johndavidback/5015988 to your computer and use it in GitHub Desktop.
Save johndavidback/5015988 to your computer and use it in GitHub Desktop.
Trying to remove a milestone and then the reference to the milestone from an event
app.post('/milestone/:action', function(req, res) {
// Get the action
if( req.params.action == 'delete' ) {
// Get the POST variables
var milestone_id = req.body.milestone_id;
var event_id = req.body.event_id;
// We need to delete the milestone
MilestoneModel.remove({_id: milestone_id }, function(err, m) {
if( ! err ) {
// THis next line always returns 'undefined' for event_id
console.log('trying to find event: ' + event_id);
EventModel.findOne({ _id: event_id }, function(err, event_object) {
if(event_object) {
event_object.update( { field: 'milestones' }, { $pull: { field: milestone_id }}, function(err, event ) {
if( ! err ) {
res.json({success: true});
} else {
console.log('Could not remove milestone from event: ' + event_id);
res.json({success: true, remove_event: false});
}
});
} else {
res.json({ success: false });
}
});
} else {
res.json({success: false, error: err});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment