File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -269,4 +269,23 @@ exports.photo =(req,res)=>{
269269 res . set ( 'Content-Type' , blog . photo . contentType )
270270 return res . send ( blog . photo . data ) ;
271271 } )
272- } ;
272+ } ;
273+
274+ exports . blogListRelated = ( req , res ) => {
275+ let limit = req . body . limit ? parseInt ( req . body . limit ) : 3
276+
277+ const { _id, categories} = req . body . blog
278+
279+ // not including _id but including categories
280+ // while showing related blogs excluding the blog itself and showing other blogs instead
281+ Blog . find ( { _id : { $ne : _id } , categories : { $in : categories } } ) . limit ( limit ) . populate ( 'postedBy' , '_id name profile' ) . select ( 'slug excerpt postedBy createdAt updatedAt' )
282+ . exec ( ( err , blogs ) => {
283+ if ( err ) {
284+ return res . status ( 400 ) . json ( {
285+ error : "Blog not found"
286+ } )
287+ res . json ( blogs )
288+ }
289+ } )
290+
291+ }
You can’t perform that action at this time.
0 commit comments