delete
This commit is contained in:
parent
2ac25c44ef
commit
f239700c3c
735
package-lock.json
generated
735
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"expect": "^1.20.2",
|
"expect": "^1.20.2",
|
||||||
"mocha": "^3.0.2",
|
"mocha": "^3.0.2",
|
||||||
"nodemon": "^1.10.2",
|
"nodemon": "^1.12.1",
|
||||||
"supertest": "^2.0.0"
|
"supertest": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
playground/mongoose-remove.js
Normal file
11
playground/mongoose-remove.js
Normal 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);
|
||||||
|
})
|
@ -37,16 +37,20 @@ app.get('/todos/:id', (req, res) => {
|
|||||||
if (!ObjectID.isValid(id)){
|
if (!ObjectID.isValid(id)){
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Todo.findById(req.params.id).then((todo) => {
|
Todo.findById(req.params.id).then((todo) => {
|
||||||
if(!todo){
|
if(!todo){ return res.status(404).send(); }
|
||||||
return res.status(404).send();
|
|
||||||
}
|
|
||||||
return res.send({todo});
|
return res.send({todo});
|
||||||
}).catch((e) => res.status(400).send())
|
}).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, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Started on port ${port}`);
|
console.log(`Started on port ${port}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user