Skip to content

Commit

Permalink
add get for recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
ygorgs committed May 16, 2017
1 parent effd629 commit 2bb0f42
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/routes/hero_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function (app) {
});

apiRoutes.get('/search/:params', passport.authenticate('jwt', { session: false }), function (req, res) {
let name = req.query.name;
var name = req.query.name;
Hero.find({ name: {$regex: name, $options: 'i'}}, function (err, heroes) {
if (err) {
throw err;
Expand All @@ -69,6 +69,25 @@ module.exports = function (app) {
})
});

apiRoutes.get('/recommendation/:params', passport.authenticate('jwt', { session: false }), function (req, res) {
var name = req.query.name.split(" ");
var id = req.query.id;
/* var condition = "";
for(var i = 0; i <name.length; i++){
condition += "this.name == " + name[i]
if(i + 1 < name.length){
condition += " || "
}
}*/
Hero.find({ name: {$regex: name[0], $options: 'i'}, $where: "this.id != " + id}, function (err, heroes) {
if (err) {
throw err;
} else {
return res.status(200).json({ success: true, result: heroes });
}
}).limit(3)
});

apiRoutes.get('/:id', passport.authenticate('jwt', { session: false }), function (req, res) {
let id = req.params.id;
Hero.findOne({ id: id }, function (err, hero) {
Expand Down

0 comments on commit 2bb0f42

Please sign in to comment.