fix: update searchBy query to allow searchBy on other column types than text
This commit is contained in:
parent
529b727928
commit
ab1c758def
@ -298,23 +298,16 @@ export async function paginate<T extends ObjectLiteral>(
|
|||||||
new Brackets((qb: SelectQueryBuilder<T>) => {
|
new Brackets((qb: SelectQueryBuilder<T>) => {
|
||||||
for (const column of searchBy) {
|
for (const column of searchBy) {
|
||||||
const propertyPath = (column as string).split('.')
|
const propertyPath = (column as string).split('.')
|
||||||
if (propertyPath.length > 1) {
|
const hasRelation =
|
||||||
const alias = queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(
|
propertyPath.length > 1 &&
|
||||||
propertyPath[0]
|
queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(propertyPath[0])
|
||||||
)
|
|
||||||
? `${qb.alias}_${column}`
|
const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}`
|
||||||
: `${qb.alias}.${column}`
|
|
||||||
const condition: WherePredicateOperator = {
|
if (['postgres', 'cockroachdb'].includes(queryBuilder.connection.options.type)) {
|
||||||
operator: 'ilike',
|
qb.orWhere(`${aliasColumn}::text ILIKE '%${query.search}%'`)
|
||||||
parameters: [alias, `:${column}`],
|
|
||||||
}
|
|
||||||
qb.orWhere(qb['createWhereConditionExpression'](condition), {
|
|
||||||
[column]: `%${query.search}%`,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
qb.orWhere({
|
qb.orWhere(`UPPER(${aliasColumn}) LIKE UPPER('%${query.search}%')`)
|
||||||
[column]: ILike(`%${query.search}%`),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user