Skip to content

Commit

Permalink
fix: pagination optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Jan 5, 2022
1 parent f7ddebc commit 8ed44f3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ class Project extends Model {
replacements
})).length;

if (limit && offset) {
sql = `${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`;
}

return {
count,
rows: await sequelize.query(`${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`, {
rows: await sequelize.query(sql, {
model: Project,
replacements: {...replacements, ...{offset, limit}},
mapToModel: true, // pass true here if you have any mapped fields
Expand All @@ -114,9 +118,13 @@ class Project extends Model {
replacements
})).length;

if (limit && offset) {
sql = `${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`;
}

return {
count,
rows: await sequelize.query(`${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`, {
rows: await sequelize.query(sql, {
model: Project,
mapToModel: true, // pass true here if you have any mapped fields
replacements: {...replacements, ...{offset, limit}}
Expand Down

0 comments on commit 8ed44f3

Please sign in to comment.