fix: do not override where clause (#69)

This commit is contained in:
Philipp 2021-08-19 19:48:50 +02:00 committed by GitHub
parent 750d7850b9
commit 75cf154585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,11 +115,8 @@ export async function paginate<T>(
}
}
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<T>(
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<T>(
}
}
queryBuilder = queryBuilder[hasWhereClause ? 'andWhere' : 'where'](filter)
queryBuilder = queryBuilder.andWhere(filter)
}
;[items, totalItems] = await queryBuilder.getManyAndCount()