Skip to content

Commit

Permalink
Completed the search functionality of all the Authors
Browse files Browse the repository at this point in the history
  • Loading branch information
barhouum7 committed Oct 5, 2020
1 parent d552225 commit 4affa2e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions routes/authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ const Author = require('../models/author')

// For All Authors Route
router.get('/', async (req, res) => {
let searchOptions = {}
if (req.query.name != null && req.query.name !== '') {
searchOptions.name = new RegExp(req.query.name, 'i' /* i == insensitive */ )
}
try {
const authors = await Author.find({} /* This means that we have no conditions, and we just pass to it an empty JavaScript Object */ )
const authors = await Author.find(searchOptions /* {} <-- This means that If we have no conditions, we just pass to it an empty JavaScript Object */ )
/* res.send('Hello World !') */ // We just sending a response
res.render('authors/index', {
authors: authors
authors: authors,
searchOptions: req.query
}) // rendering our view
} catch {
res.redirect('/')
Expand Down

0 comments on commit 4affa2e

Please sign in to comment.