Skip to content

Commit

Permalink
Merge pull request dan-divy#19 from MayorChano/master
Browse files Browse the repository at this point in the history
Better search
  • Loading branch information
littledivy committed Apr 22, 2019
2 parents 73dacf1 + 1f09b0f commit 07dee78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions routes/api/v1/index.js
Expand Up @@ -58,13 +58,25 @@ router.post('/v1/follow', function(req, res, next) {
});

router.get('/v1/search', function(req, res, next) {
db.search(req.query.q, (err, results) => {
res.send(results);
})
let q = req.query.q.toLowerCase()
db.getAll((err, all) => {
if(!q) return res.send(all);
all = all.filter(x =>
x.firstname &&
x.username &&
x.lastname &&
(x.firstname.toLowerCase().startsWith(q) ||
x.firstname.toLowerCase().endsWith(q) ||
x.lastname.toLowerCase().startsWith(q) ||
x.lastname.toLowerCase().endsWith(q) ||
x.username.toLowerCase().startsWith(q) ||
x.username.toLowerCase().endsWith(q)))
return res.send(all);
});
});

router.get('/v1/oauth/:service', function(req, res, next) {
if(req.params.service == 'instagram') res.redirect(ig.auth_url);
if(req.params.service == 'instagram') res.redirect(ig.instagram.auth_url);
if(req.params.service == 'google') res.redirect(g.auth_url);
});

Expand Down
2 changes: 1 addition & 1 deletion views/user/list.ejs
Expand Up @@ -22,7 +22,7 @@

</ul>
<ul class="list-group">
<li class="list-group-item list-group-item-primary">Top Users</li>
<li class="list-group-item list-group-item-primary">Results</li>
<div id="user-list">
<% for(var i=0;i<list.length;i++) { %>
<li class="list-group-item">
Expand Down

0 comments on commit 07dee78

Please sign in to comment.