feat: Search by billing_address and shipping_address on Order model (#12814)
* feat: Search by billing_address and shipping_address on Order model **What** Added `.searchable()` method to the `shipping_address` and `billing_address` relationships in the `Order` model, enabling search functionality. **Why** Previously searching via `shipping_address` and `billing_address` was not supported, limiting the ability to find orders based on shipping or billing address information. Resolves SUP-1838 * Update integration tests to include billing_address and non-existing addresses.
This commit is contained in:
1 parent
ba1e6595b7
commit
fbf33885f5
2 files changed
+65
No files matched your search
@@ -66,6 +66,69 @@ medusaIntegrationTestRunner({
|
|||||||
expect(response.data.orders).toHaveLength(0)
|
expect(response.data.orders).toHaveLength(0)
|
||||||
expect(response.data.orders).toEqual([])
|
expect(response.data.orders).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should search orders by shipping address", async () => {
|
||||||
|
let response = await api.get(`/admin/orders?fields=+shipping_address.address_1,+shipping_address.address_2`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data.orders).toHaveLength(1)
|
||||||
|
expect(response.data.orders).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: order.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
response = await api.get(`/admin/orders?fields=+shipping_address.address_1,+shipping_address.address_2&q=${order.shipping_address.address_1}`, 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.shipping_address.address_2}`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data.orders).toHaveLength(1)
|
||||||
|
expect(response.data.orders).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: order.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
response = await api.get(`/admin/orders?q=does-not-exist`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data.orders).toHaveLength(0)
|
||||||
|
expect(response.data.orders).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should search orders by billing address", async () => {
|
||||||
|
let response = await api.get(`/admin/orders?fields=+billing_address.address_1,+billing_address.address_2`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data.orders).toHaveLength(1)
|
||||||
|
expect(response.data.orders).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: order.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
response = await api.get(`/admin/orders?fields=+billing_address.address_1,+billing_address.address_2&q=${order.billing_address.address_1}`, 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.billing_address.address_2}`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data.orders).toHaveLength(1)
|
||||||
|
expect(response.data.orders).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: order.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /orders/:id", () => {
|
describe("POST /orders/:id", () => {
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ const _Order = model
|
|||||||
mappedBy: undefined,
|
mappedBy: undefined,
|
||||||
foreignKey: true,
|
foreignKey: true,
|
||||||
})
|
})
|
||||||
|
.searchable()
|
||||||
.nullable(),
|
.nullable(),
|
||||||
billing_address: model
|
billing_address: model
|
||||||
.hasOne<any>(() => OrderAddress, {
|
.hasOne<any>(() => OrderAddress, {
|
||||||
mappedBy: undefined,
|
mappedBy: undefined,
|
||||||
foreignKey: true,
|
foreignKey: true,
|
||||||
})
|
})
|
||||||
|
.searchable()
|
||||||
.nullable(),
|
.nullable(),
|
||||||
summary: model.hasMany<any>(() => OrderSummary, {
|
summary: model.hasMany<any>(() => OrderSummary, {
|
||||||
mappedBy: "order",
|
mappedBy: "order",
|
||||||
|
|||||||
Reference in new issue
Block a user