fix(utils): Typecasting non-text fields in FTS (#12729)
This commit is contained in:
1 parent
ebd4d70b6b
commit
b79215dd5c
4 files changed
+68
-5
No files matched your search
@@ -30,6 +30,44 @@ medusaIntegrationTestRunner({
|
|||||||
).data.shipping_profile
|
).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", () => {
|
describe("POST /orders/:id", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
seeder = await createOrderSeeder({
|
seeder = await createOrderSeeder({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type {
|
|||||||
FindOneOptions,
|
FindOneOptions,
|
||||||
FindOptions,
|
FindOptions,
|
||||||
} from "@mikro-orm/core"
|
} 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"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
|
|
||||||
export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_"
|
export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_"
|
||||||
@@ -54,9 +54,10 @@ function retrieveRelationsConstraints(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isText = propertyConfiguration?.columnTypes?.includes("text")
|
const isText = propertyConfiguration?.columnTypes?.includes("text")
|
||||||
|
|
||||||
const columnName = isText
|
const columnName = isText
|
||||||
? propertyConfiguration.name
|
? propertyConfiguration.name
|
||||||
: `${propertyConfiguration.name}::text`
|
: raw((alias) => `cast(${alias}.${propertyConfiguration.name} as text)`)
|
||||||
|
|
||||||
relationFreeTextSearchWhere.push({
|
relationFreeTextSearchWhere.push({
|
||||||
[columnName]: {
|
[columnName]: {
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import { PrimaryKeyModifier } from "./primary-key"
|
|||||||
export class AutoIncrementProperty extends BaseProperty<number> {
|
export class AutoIncrementProperty extends BaseProperty<number> {
|
||||||
protected dataType: {
|
protected dataType: {
|
||||||
name: "serial"
|
name: "serial"
|
||||||
options: {}
|
options: {
|
||||||
|
searchable?: boolean
|
||||||
|
primaryKey?: boolean
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +33,27 @@ export class AutoIncrementProperty extends BaseProperty<number> {
|
|||||||
return new PrimaryKeyModifier<number, AutoIncrementProperty>(this)
|
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 }) {
|
constructor(options?: { primaryKey?: boolean }) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { model, OrderStatus } from "@medusajs/framework/utils"
|
import { model, OrderStatus } from "@medusajs/framework/utils"
|
||||||
|
import { Return } from "@models"
|
||||||
import { OrderAddress } from "./address"
|
import { OrderAddress } from "./address"
|
||||||
import { OrderCreditLine } from "./credit-line"
|
import { OrderCreditLine } from "./credit-line"
|
||||||
import { OrderItem } from "./order-item"
|
import { OrderItem } from "./order-item"
|
||||||
import { OrderShipping } from "./order-shipping-method"
|
import { OrderShipping } from "./order-shipping-method"
|
||||||
import { OrderSummary } from "./order-summary"
|
import { OrderSummary } from "./order-summary"
|
||||||
import { OrderTransaction } from "./transaction"
|
import { OrderTransaction } from "./transaction"
|
||||||
import { Return } from "@models"
|
|
||||||
|
|
||||||
const _Order = model
|
const _Order = model
|
||||||
.define("Order", {
|
.define("Order", {
|
||||||
id: model.id({ prefix: "order" }).primaryKey(),
|
id: model.id({ prefix: "order" }).primaryKey(),
|
||||||
display_id: model.autoincrement(),
|
display_id: model.autoincrement().searchable(),
|
||||||
region_id: model.text().nullable(),
|
region_id: model.text().nullable(),
|
||||||
customer_id: model.text().nullable(),
|
customer_id: model.text().nullable(),
|
||||||
version: model.number().default(1),
|
version: model.number().default(1),
|
||||||
|
|||||||
Reference in new issue
Block a user