fix: update searchBy query to allow searchBy on other column types than text

This commit is contained in:
Jakob Wagner 2023-01-13 15:53:41 +01:00 committed by GitHub
parent 529b727928
commit ab1c758def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -298,23 +298,16 @@ export async function paginate<T extends ObjectLiteral>(
new Brackets((qb: SelectQueryBuilder<T>) => {
for (const column of searchBy) {
const propertyPath = (column as string).split('.')
if (propertyPath.length > 1) {
const alias = queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(
propertyPath[0]
)
? `${qb.alias}_${column}`
: `${qb.alias}.${column}`
const condition: WherePredicateOperator = {
operator: 'ilike',
parameters: [alias, `:${column}`],
}
qb.orWhere(qb['createWhereConditionExpression'](condition), {
[column]: `%${query.search}%`,
})
const hasRelation =
propertyPath.length > 1 &&
queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(propertyPath[0])
const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}`
if (['postgres', 'cockroachdb'].includes(queryBuilder.connection.options.type)) {
qb.orWhere(`${aliasColumn}::text ILIKE '%${query.search}%'`)
} else {
qb.orWhere({
[column]: ILike(`%${query.search}%`),
})
qb.orWhere(`UPPER(${aliasColumn}) LIKE UPPER('%${query.search}%')`)
}
}
})