diff --git a/src/models/projects/projects.model.js b/src/models/projects/projects.model.js index 6c7b6861..db272c0e 100644 --- a/src/models/projects/projects.model.js +++ b/src/models/projects/projects.model.js @@ -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 @@ -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}}