Skip to content

Commit ac7b897

Browse files
committed
CRUD API's done
1 parent f91b4cb commit ac7b897

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

CRUD API's/app/controllers/controller.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports.create=function(req,res){
2222
newnote.save()
2323
.then(data=> {res.status(200).send(data)})
2424
.catch(err=>{
25-
res.status(400).json({"message" : "Some error occurred while creating the Note"});
25+
res.status(404).json({"message" : "Some error occurred while creating the Note"});
2626
});
2727

2828
});
@@ -35,7 +35,7 @@ exports.findAll=function(req,res){
3535
.then(notes=>{
3636
res.status(200).send(notes);
3737
}).catch(err=>{
38-
res.status(400).json({"message": "Some error occurred while retrieving notes."});
38+
res.status(404).json({"message": "Some error occurred while retrieving notes."});
3939
});
4040
};
4141

@@ -45,7 +45,7 @@ exports.findone=function(req,res){
4545
Note.findById(req.params.noteId)
4646
.then(note=>{
4747
if(!note){
48-
return res.status(400).send({message:"Note not found with id " + req.params.noteId});
48+
return res.status(404).send({message:"Note not found with id " + req.params.noteId});
4949
}
5050
res.status(200).send(note);
5151
}).catch(err=>{
@@ -62,19 +62,19 @@ exports.findone=function(req,res){
6262
//request to find ny the name of author
6363
exports.findbyauthor=function(req,res){
6464
Note.find({author:req.params.author},function(err,note){
65-
if(note) return res.status(400).send(note);
65+
if(!note) return res.status(404).send({message:"not found"});
6666
else{
67-
return res.status(400).send({message : "No author with given name has been found"});
67+
return res.status(200).send(note);
6868
}
6969
});
7070
};
7171

7272
// request to find by the name of title of note
7373
exports.findbytitle=function(req,res){
7474
Note.find({title:req.params.title},function(err,note){
75-
if(note) return res.status(400).send(note);
75+
if(note) return res.status(200).send(note);
7676

77-
res.status(400).send({message : "No note with given title name has been found"});
77+
res.status(404).send({message : "No note with given title name has been found"});
7878

7979
});
8080
};
@@ -93,9 +93,9 @@ exports.update=function(req,res){
9393
},{new: true})
9494
.then(note=>{
9595
if(!note){
96-
return res.status(400).send({message: "note not found with id "+req.params.noteId});
96+
return res.status(404).send({message: "note not found with id "+req.params.noteId});
9797
}
98-
res.send(note);
98+
res.status(200).send(note);
9999
}).catch(err => {
100100
if(err.kind === 'ObjectId') {
101101
return res.status(404).send({
@@ -115,7 +115,7 @@ exports.delete=function(req,res){
115115
Note.findByIdAndDelete(req.params.noteId)
116116
.then(note=>{
117117
if(!note){
118-
return res.status(400).send({message :"Note not found with id"+req.params.noteId});
118+
return res.status(404).send({message :"Note not found with id"+req.params.noteId});
119119
}
120120
res.send({message : "note deleted successfully"});
121121
}).catch(err => {

0 commit comments

Comments
 (0)