fix(order): searchable fields (#9493)

FIXES: TRI-353
This commit is contained in:
Carlos R. L. Rodrigues
2024-10-07 14:45:20 -03:00
committed by GitHub
parent dc9c23be34
commit 8fbef8a667
6 changed files with 45 additions and 11 deletions

View File

@@ -402,7 +402,7 @@ class SearchableEntity1 {
deleted_at: Date | null
@Searchable()
@Property()
@Property({ columnType: "text" })
searchableField: string
@Searchable()
@@ -430,7 +430,7 @@ class SearchableEntity2 {
deleted_at: Date | null
@Searchable()
@Property()
@Property({ columnType: "text" })
searchableField: string
@ManyToOne(() => SearchableEntity1, { mapToPk: true })
@@ -450,12 +450,12 @@ export {
Entity2,
Entity2WithUnDecoratedProp,
InternalCircularDependencyEntity1,
RecursiveEntity1,
RecursiveEntity2,
SearchableEntity1,
SearchableEntity2,
Product,
ProductOption,
ProductOptionValue,
ProductVariant,
RecursiveEntity1,
RecursiveEntity2,
SearchableEntity1,
SearchableEntity2,
}

View File

@@ -1,11 +1,11 @@
import { EntityMetadata, EntitySchema, ReferenceType } from "@mikro-orm/core"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import type {
FindOptions,
EntityClass,
EntityProperty,
FindOneOptions,
FindOptions,
} from "@mikro-orm/core"
import { EntityMetadata, EntitySchema, ReferenceType } from "@mikro-orm/core"
import { SqlEntityManager } from "@mikro-orm/postgresql"
export const FreeTextSearchFilterKey = "freeTextSearch"
@@ -57,8 +57,13 @@ function retrieveRelationsConstraints(
continue
}
const isText = propertyConfiguration?.columnTypes?.includes("text")
const columnName = isText
? propertyConfiguration.name
: `${propertyConfiguration.name}::text`
relationFreeTextSearchWhere.push({
[propertyConfiguration.name]: {
[columnName]: {
$ilike: `%${searchValue}%`,
},
})