This commit is contained in:
Tyrel Souza 2017-11-30 23:29:42 -05:00
parent 2ac25c44ef
commit f239700c3c
4 changed files with 465 additions and 299 deletions

737
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^3.0.2",
"nodemon": "^1.10.2",
"nodemon": "^1.12.1",
"supertest": "^2.0.0"
}
}

View File

@ -0,0 +1,11 @@
const {ObjectID} = require('mongodb');
const {mongoose} = require('./../server/db/mongoose');
var {Todo} = require('./../server/models/todo');
Todo.remove({}).then((result) => {
console.log(result);
})
Todo.findByIdAndRemove('5a20d2583ddedb1c41bda7dc').then((result) => {
console.log(result);
})

View File

@ -37,16 +37,20 @@ app.get('/todos/:id', (req, res) => {
if (!ObjectID.isValid(id)){
return res.status(404).send();
}
Todo.findById(req.params.id).then((todo) => {
if(!todo){
return res.status(404).send();
}
if(!todo){ return res.status(404).send(); }
return res.send({todo});
}).catch((e) => res.status(400).send())
});
app.delete('/todos/:id', (req, res) => {
var id = req.params.id;
if (!ObjectID.isValid(id)){ return res.status(404).send(); }
Todo.findByIdAndRemove(id).then((todo) => {
if(!todo){ return res.status(404).send(); }
return res.send({todo});
}).catch((e) => res.status(400).send())
});
app.listen(port, () => {
console.log(`Started on port ${port}`);