Skip to content

Commit

Permalink
Merge pull request #5 from danivijay/search-items
Browse files Browse the repository at this point in the history
feat: add search to BE
  • Loading branch information
danivijay committed Jul 12, 2020
2 parents ff093bd + c19c85e commit 93f1ccf
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions controllers/recommendationSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ const { Movie } = require('../models/movie');
exports.getItems = async (req, res, next) => {
try {
const page = req.query.pageNum || 0;
const movies = await Movie.find().skip(page * 10).limit(10).sort('title');
res.status(200).json({
success: true,
movies: movies
});
if(req.query.search != ''){
searchKey = req.query.search;
var searchKey = new RegExp(req.query.search, "g");
const movies = await Movie.find({title:searchKey}).skip(page * 10).limit(10).sort('title');
res.status(200).json({
success: true,
movies: movies
});
}
else{
const movies = await Movie.find().skip(page * 10).limit(10).sort('title');
res.status(200).json({
success: true,
movies: movies
});
}

} catch (error) {
console.log(`Error on getting items: ${error.message}`.red);
res.status(500).json({
Expand Down

0 comments on commit 93f1ccf

Please sign in to comment.