Skip to content

Commit

Permalink
bug(tags): search by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
minega25 committed Nov 14, 2019
1 parent 16e8bec commit 12b213e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
20 changes: 11 additions & 9 deletions src/controllers/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ class Search {
}
})
);
const users = await UserModel.searchUser(searchQuery.user, offset, limit);
const foundUsers = _.map(
users,
_.partialRight(_.pick, ["username", "image", "bio"])
);
let duplicateFoundTags = [];
foundArticles.map(article => {
const allArticles = await ArticleModel.getAllArticles();
allArticles.map(article => {
const articleTags = article.taglist;
const found = articleTags.filter(
articleTag => articleTag === searchQuery.tag
);
const found = articleTags
? articleTags.filter(articleTag => articleTag === searchQuery.tag)
: [];
if (found.length >= 1) {
for (let i = 0; i <= found.length - 1; i++) {
duplicateFoundTags = [found[i], ...duplicateFoundTags];
Expand All @@ -84,11 +90,7 @@ class Search {
if (foundTags[0] === "") {
foundTags = [];
}
const users = await UserModel.searchUser(searchQuery.user, offset, limit);
const foundUsers = _.map(
users,
_.partialRight(_.pick, ["username", "image", "bio"])
);

util.setSuccess(200, "Search successful", {
foundArticles,
foundUsers,
Expand Down
47 changes: 24 additions & 23 deletions src/seeders/20190820133339-demo-article-2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12b213e

Please sign in to comment.