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 274996e
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/controllers/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,18 @@ class Search {
}
})
);
let duplicateFoundTags = [];
foundArticles.map(article => {
const articleTags = article.taglist;
const found = articleTags.filter(
articleTag => articleTag === searchQuery.tag
);
if (found.length >= 1) {
for (let i = 0; i <= found.length - 1; i++) {
duplicateFoundTags = [found[i], ...duplicateFoundTags];
}
}
});

let foundTags = duplicateFoundTags.filter(
(item, index) => duplicateFoundTags.indexOf(item) === index
);
if (foundTags[0] === "") {
foundTags = [];
}
const users = await UserModel.searchUser(searchQuery.user, offset, limit);
const foundUsers = _.map(
users,
_.partialRight(_.pick, ["username", "image", "bio"])
);
const tags = await TagModel.searchTag(
"Tag",
searchQuery.tag,
offset,
limit
);
const foundTags = _.map(tags, _.partialRight(_.pick, ["name"]));
util.setSuccess(200, "Search successful", {
foundArticles,
foundUsers,
Expand Down

0 comments on commit 274996e

Please sign in to comment.