From 75cf15458520be507e5f10681a372023a16abe8a Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 19 Aug 2021 19:48:50 +0200 Subject: [PATCH] fix: do not override where clause (#69) --- src/paginate.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/paginate.ts b/src/paginate.ts index 7448e60..615ec46 100644 --- a/src/paginate.ts +++ b/src/paginate.ts @@ -115,11 +115,8 @@ export async function paginate( } } - let hasWhereClause = false - if (config.where) { - queryBuilder = queryBuilder.where(config.where) - hasWhereClause = true + queryBuilder = queryBuilder.andWhere(config.where) } if (query.search && config.searchableColumns) { @@ -127,8 +124,7 @@ export async function paginate( for (const column of config.searchableColumns) { search.push({ [column]: ILike(`%${query.search}%`) }) } - queryBuilder = queryBuilder[hasWhereClause ? 'andWhere' : 'where'](search) - hasWhereClause = true + queryBuilder = queryBuilder.andWhere(search) } if (query.filter) { @@ -196,7 +192,7 @@ export async function paginate( } } - queryBuilder = queryBuilder[hasWhereClause ? 'andWhere' : 'where'](filter) + queryBuilder = queryBuilder.andWhere(filter) } ;[items, totalItems] = await queryBuilder.getManyAndCount()