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

@@ -140,6 +140,23 @@ medusaIntegrationTestRunner({
.order
})
it("should find the order querying it by number", async () => {
const userEmail = "tony@stark-industries.com"
const response = (
await api.get(`/admin/orders/?q=non-existing`, adminHeaders)
).data
expect(response.orders).toHaveLength(0)
const response2 = (
await api.get(`/admin/orders/?fields=+email&q=@stark`, adminHeaders)
).data
expect(response2.orders).toHaveLength(1)
expect(response2.orders[0].email).toEqual(userEmail)
})
it("should only create fulfillments grouped by shipping requirement", async () => {
const {
response: { data },

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}%`,
},
})

View File

@@ -2,6 +2,7 @@ import { DAL } from "@medusajs/framework/types"
import {
createPsqlIndexStatementHelper,
generateEntityId,
Searchable,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
@@ -30,33 +31,42 @@ export default class OrderAddress {
@CustomerIdIndex.MikroORMIndex()
customer_id: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
company: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
first_name: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
last_name: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
address_1: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
address_2: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text", nullable: true })
country_code: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
province: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
postal_code: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
phone: string | null = null

View File

@@ -1,6 +1,7 @@
import { DAL } from "@medusajs/framework/types"
import {
OrderStatus,
Searchable,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/framework/utils"
@@ -90,6 +91,7 @@ export default class Order {
@PrimaryKey({ columnType: "text" })
id: string
@Searchable()
@Property({ autoincrement: true, primary: false })
@DisplayIdIndex.MikroORMIndex()
display_id: number
@@ -130,6 +132,7 @@ export default class Order {
@IsDraftOrderIndex.MikroORMIndex()
is_draft_order: boolean = false
@Searchable()
@Property({ columnType: "text", nullable: true })
email: string | null = null

View File

@@ -70,7 +70,6 @@ export default class ReturnReason {
cascade: [Cascade.PERSIST],
})
parent_return_reason?: Rel<ReturnReason> | null
Searchable
@OneToMany(
() => ReturnReason,
(return_reason) => return_reason.parent_return_reason,