From 32bc2b00f0005f233bbe70b120d9f015b3f47252 Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Wed, 5 Jan 2022 10:01:54 -0500 Subject: [PATCH 1/3] fts fixes --- src/models/projects/projects.model.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/models/projects/projects.model.js b/src/models/projects/projects.model.js index 5c1f8303..70400da9 100644 --- a/src/models/projects/projects.model.js +++ b/src/models/projects/projects.model.js @@ -91,7 +91,7 @@ class Project extends Model { }; } - static findAllSqliteFts(searchStr, orgUid, pagination) { + static async findAllSqliteFts(searchStr, orgUid, pagination) { const { offset, limit } = pagination; let sql = `SELECT * FROM projects_fts WHERE projects_fts MATCH :search`; @@ -100,12 +100,17 @@ class Project extends Model { } sql = `${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`; + + const count = await Project.count(); - return sequelize.query(sql, { - model: Project, - replacements: { search: `${searchStr}*`, orgUid, offset, limit }, - mapToModel: true, // pass true here if you have any mapped fields - }); + return { + count, + rows: sequelize.query(sql, { + model: Project, + replacements: { search: `${searchStr}*`, orgUid, offset, limit }, + mapToModel: true, // pass true here if you have any mapped fields + }), + }; } } From 8ace0d9fa9205afcd691a47050087042bdf79e24 Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Wed, 5 Jan 2022 10:45:04 -0500 Subject: [PATCH 2/3] fix: more fts fixes --- src/models/projects/projects.model.js | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/models/projects/projects.model.js b/src/models/projects/projects.model.js index 70400da9..1413ee09 100644 --- a/src/models/projects/projects.model.js +++ b/src/models/projects/projects.model.js @@ -76,16 +76,20 @@ class Project extends Model { if (orgUid) { sql = `${sql} AND orgUid = :orgUid`; } - - sql = `${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`; - - const count = await Project.count(); + + const replacements = { search: searchStr, orgUid }; + + const count = (await sequelize.query(sql, { + model: Project, + mapToModel: true, // pass true here if you have any mapped fields + replacements + })).length; return { count, - rows: await sequelize.query(sql, { + rows: await sequelize.query(`${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`, { model: Project, - replacements: { search: searchStr, orgUid, offset, limit }, + replacements: {...replacements, ...{offset, limit}}, mapToModel: true, // pass true here if you have any mapped fields }), }; @@ -98,17 +102,21 @@ class Project extends Model { if (orgUid) { sql = `${sql} AND orgUid = :orgUid`; } - - sql = `${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`; + + const replacements = { search: `${searchStr}*`, orgUid }; - const count = await Project.count(); - + const count = (await sequelize.query(sql, { + model: Project, + mapToModel: true, // pass true here if you have any mapped fields + replacements + })).length; + return { count, - rows: sequelize.query(sql, { + rows: await sequelize.query(`${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`, { model: Project, - replacements: { search: `${searchStr}*`, orgUid, offset, limit }, mapToModel: true, // pass true here if you have any mapped fields + replacements: {...replacements, ...{offset, limit}} }), }; } From e67f5cb3fee1e121ca56c4e1d36b53291c9f17a9 Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Wed, 5 Jan 2022 10:57:33 -0500 Subject: [PATCH 3/3] pagination fix for unincluded --- src/controllers/helpers.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index cfa58503..85a99c2b 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -1,6 +1,13 @@ 'use strict'; export const paginationParams = (page, limit) => { + if (page === undefined || limit === undefined) { + return { + page: undefined, + limit: undefined, + } + } + if (page < 1) { page = 1; }