fix(utils): Typecasting non-text fields in FTS (#12729)
This commit is contained in:
@@ -30,6 +30,44 @@ medusaIntegrationTestRunner({
|
||||
).data.shipping_profile
|
||||
})
|
||||
|
||||
describe("GET /admin/orders", () => {
|
||||
beforeEach(async () => {
|
||||
seeder = await createOrderSeeder({
|
||||
api,
|
||||
container: getContainer(),
|
||||
})
|
||||
order = seeder.order
|
||||
})
|
||||
|
||||
it("should search orders by display_id", async () => {
|
||||
let response = await api.get(`/admin/orders`, adminHeaders)
|
||||
|
||||
expect(response.data.orders).toHaveLength(1)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
}),
|
||||
])
|
||||
|
||||
response = await api.get(
|
||||
`/admin/orders?q=${order.display_id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.data.orders).toHaveLength(1)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
}),
|
||||
])
|
||||
|
||||
response = await api.get(`/admin/orders?q=2345`, adminHeaders)
|
||||
|
||||
expect(response.data.orders).toHaveLength(0)
|
||||
expect(response.data.orders).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /orders/:id", () => {
|
||||
beforeEach(async () => {
|
||||
seeder = await createOrderSeeder({
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
FindOneOptions,
|
||||
FindOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { EntityMetadata, ReferenceKind } from "@mikro-orm/core"
|
||||
import { EntityMetadata, raw, ReferenceKind } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_"
|
||||
@@ -54,9 +54,10 @@ function retrieveRelationsConstraints(
|
||||
}
|
||||
|
||||
const isText = propertyConfiguration?.columnTypes?.includes("text")
|
||||
|
||||
const columnName = isText
|
||||
? propertyConfiguration.name
|
||||
: `${propertyConfiguration.name}::text`
|
||||
: raw((alias) => `cast(${alias}.${propertyConfiguration.name} as text)`)
|
||||
|
||||
relationFreeTextSearchWhere.push({
|
||||
[columnName]: {
|
||||
|
||||
@@ -8,7 +8,10 @@ import { PrimaryKeyModifier } from "./primary-key"
|
||||
export class AutoIncrementProperty extends BaseProperty<number> {
|
||||
protected dataType: {
|
||||
name: "serial"
|
||||
options: {}
|
||||
options: {
|
||||
searchable?: boolean
|
||||
primaryKey?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +33,27 @@ export class AutoIncrementProperty extends BaseProperty<number> {
|
||||
return new PrimaryKeyModifier<number, AutoIncrementProperty>(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates that a serial property is searchable.
|
||||
*
|
||||
* @example
|
||||
* import { model } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const MyCustom = model.define("my_custom", {
|
||||
* name: model.autoincrement().searchable(),
|
||||
* // ...
|
||||
* })
|
||||
*
|
||||
* export default MyCustom
|
||||
*
|
||||
* @customNamespace Property Configuration Methods
|
||||
*/
|
||||
searchable() {
|
||||
this.dataType.options.searchable = true
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
constructor(options?: { primaryKey?: boolean }) {
|
||||
super()
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { model, OrderStatus } from "@medusajs/framework/utils"
|
||||
import { Return } from "@models"
|
||||
import { OrderAddress } from "./address"
|
||||
import { OrderCreditLine } from "./credit-line"
|
||||
import { OrderItem } from "./order-item"
|
||||
import { OrderShipping } from "./order-shipping-method"
|
||||
import { OrderSummary } from "./order-summary"
|
||||
import { OrderTransaction } from "./transaction"
|
||||
import { Return } from "@models"
|
||||
|
||||
const _Order = model
|
||||
.define("Order", {
|
||||
id: model.id({ prefix: "order" }).primaryKey(),
|
||||
display_id: model.autoincrement(),
|
||||
display_id: model.autoincrement().searchable(),
|
||||
region_id: model.text().nullable(),
|
||||
customer_id: model.text().nullable(),
|
||||
version: model.number().default(1),
|
||||
|
||||
Reference in New Issue
Block a user