File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,41 @@ exports.findAll=function(req,res){
3535// find a note by id
3636exports . findone = function ( req , res ) {
3737
38+ Note . findById ( req . params . noteId )
39+ . then ( note => {
40+ if ( ! note ) {
41+ return res . status ( 400 ) . send ( { message :"Note not found with id " + req . params . noteId } ) ;
42+ }
43+ res . status ( 200 ) . send ( note ) ;
44+ } ) . catch ( err => {
45+ if ( err . kind == 'ObjectId' ) {
46+ return res . status ( 404 ) . send ( { message : "Note not found with id " + req . params . noteId } ) ;
47+ }
48+ return res . status ( 500 ) . send ( {
49+ message : "Error retrieving note with id " + req . params . noteId
50+ } ) ;
51+ } ) ;
52+
53+ } ;
3854
55+ //request to find ny the name of author
56+ exports . findbyauthor = function ( req , res ) {
57+ Note . find ( { author :req . params . author } , function ( err , note ) {
58+ if ( note ) return res . status ( 400 ) . send ( note ) ;
59+
60+ res . status ( 400 ) . send ( { message : "No author with given name has been found" } ) ;
61+
62+ } ) ;
63+ } ;
64+
65+ // request to find by the name of title of note
66+ exports . findbytitle = function ( req , res ) {
67+ Note . find ( { title :req . params . title } , function ( err , note ) {
68+ if ( note ) return res . status ( 400 ) . send ( note ) ;
69+
70+ res . status ( 400 ) . send ( { message : "No author with given name has been found" } ) ;
71+
72+ } ) ;
3973} ;
4074
4175exports . update = function ( req , res ) {
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ module.exports=(app)=>{
88 app . get ( '/api/notes' , notes . findAll ) ;
99
1010 //retrive a single note by id
11- app . get ( '/api/notes/:noteId' , notes . findone ) ;
11+ app . get ( '/api/find/:noteId' , notes . findone ) ;
12+
13+ //retrive all notes by a particular author
14+ app . get ( '/api/findauthor/:author' , notes . findbyauthor ) ;
15+
16+ // retrive all notes by the note title
17+ app . get ( '/api/findbytitle/:title' , notes . findbytitle ) ;
1218
1319 //update a note with noteId
1420 app . put ( '/api/notes/:noteId' , notes . update ) ;
You can’t perform that action at this time.
0 commit comments