-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#165412920 article rating pagination
- Loading branch information
Showing
9 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import db from '../../models'; | ||
|
||
export default async (limit, offset, articleId) => { | ||
const allRatings = await db.Rating.findAll({ | ||
limit, | ||
offset, | ||
where: { | ||
articleId | ||
}, | ||
logging: false, | ||
attributes: ['id', 'rating', 'createdAt'], | ||
include: [ | ||
{ | ||
model: db.User, | ||
as: 'author', | ||
attributes: ['username', 'firstName', 'lastName', 'bio', 'image', 'createdAt'] | ||
} | ||
] | ||
}); | ||
return allRatings; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import db from '../../models'; | ||
import * as filters from '../../helpers/searchArticleFilters'; | ||
|
||
/** | ||
* Get specific article ratings | ||
* @param {object} limit limit for query | ||
* @param {object} offset offset for query | ||
* @param {object} condition contains author, tag and keyword to filter query | ||
* @returns {object} Object representing the response returned | ||
*/ | ||
export default async (limit, offset, { keyword, author, tag }) => { | ||
const where = filters.filterQueryBuilder({ keyword, author, tag }); | ||
const paginate = { limit, offset }; | ||
let response = []; | ||
response = await db.Article.findAll({ | ||
paginate, | ||
where, | ||
order: [['rating', 'DESC']], | ||
logging: false, | ||
include: [ | ||
{ | ||
model: db.User, | ||
as: 'author', | ||
attributes: ['username', 'bio', 'image'] | ||
} | ||
] | ||
}); | ||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters