Skip to content

Commit

Permalink
Merge pull request #75 from andela/bug/168205113/fix-search-functiona…
Browse files Browse the repository at this point in the history
…lity

168205113 fix search functionality
  • Loading branch information
caleb-42 authored and Obi chinedu Frank committed Sep 4, 2019
2 parents e5fbaff + b4ad5f5 commit 0d79598
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion controllers/articles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ export default {
{
model: db.User,
as: 'author',
attributes: ['firstName', 'lastName', ['image', 'authorImage']]
attributes: ['firstName', 'lastName', 'username', ['image', 'authorImage']]
},
{
model: db.Category,
Expand Down
17 changes: 9 additions & 8 deletions controllers/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const authorFilter = async (req, res, next) => {
model: db.User,
as: 'author',
where:
(author) ? {
[Op.or]: [
{ firstName: { [Op.iLike]: `%${author}%` } },
{ lastName: { [Op.iLike]: `%${author}%` } },
{ username: { [Op.iLike]: `%${author}%` } }
]
}
: {},
(author) ? {
[Op.or]: [
{ firstName: { [Op.iLike]: `%${author}%` } },
{ lastName: { [Op.iLike]: `%${author}%` } },
{ username: { [Op.iLike]: `%${author}%` } }
]
}
: {},
attributes: ['username', 'firstName', 'lastName']
});
return next();
Expand All @@ -56,5 +56,6 @@ export const end = async (req, res) => {
}
);

include = [];
res.status(200).json({ search });
};

0 comments on commit 0d79598

Please sign in to comment.