diff --git a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts index 62dd5e7bd8..4fa3429b7d 100644 --- a/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts +++ b/integration-tests/http/__tests__/reservations/admin/reservations.spec.ts @@ -4,7 +4,7 @@ import { createAdminUser, } from "../../../../helpers/create-admin-user" -jest.setTimeout(30000) +jest.setTimeout(50000) medusaIntegrationTestRunner({ testSuite: ({ dbConnection, getContainer, api }) => { @@ -329,6 +329,90 @@ medusaIntegrationTestRunner({ ) }) + it("lists reservation items with free text search on SKU on inventory item", async () => { + const reservationsRes = await api + .get(`/admin/reservations?q=second`, adminHeaders) + .catch(console.warn) + + expect(reservationsRes.data.reservations.length).toBe(1) + expect(reservationsRes.data.reservations).toEqual([ + { + id: reservation2.id, + created_at: expect.any(String), + description: "test description", + inventory_item: { + created_at: expect.any(String), + description: null, + height: null, + hs_code: "hs001", + id: inventoryItem2.id, + length: null, + material: null, + metadata: null, + mid_code: null, + origin_country: "UK", + requires_shipping: true, + reserved_quantity: 1, + sku: "second", + stocked_quantity: 100, + thumbnail: null, + title: null, + updated_at: expect.any(String), + weight: null, + width: null, + }, + inventory_item_id: inventoryItem2.id, + line_item_id: "line-item-id-2", + location_id: stockLocation1.id, + metadata: null, + quantity: 1, + updated_at: expect.any(String), + }, + ]) + }) + + it("lists reservation items with free text search on descroption", async () => { + const reservationsRes = await api + .get(`/admin/reservations?q=test`, adminHeaders) + .catch(console.warn) + + expect(reservationsRes.data.reservations.length).toBe(1) + expect(reservationsRes.data.reservations).toEqual([ + { + id: reservation2.id, + created_at: expect.any(String), + description: "test description", + inventory_item: { + created_at: expect.any(String), + description: null, + height: null, + hs_code: "hs001", + id: inventoryItem2.id, + length: null, + material: null, + metadata: null, + mid_code: null, + origin_country: "UK", + requires_shipping: true, + reserved_quantity: 1, + sku: "second", + stocked_quantity: 100, + thumbnail: null, + title: null, + updated_at: expect.any(String), + weight: null, + width: null, + }, + inventory_item_id: inventoryItem2.id, + line_item_id: "line-item-id-2", + location_id: stockLocation1.id, + metadata: null, + quantity: 1, + updated_at: expect.any(String), + }, + ]) + }) + it("lists reservations with inventory_items", async () => { const res = await api.get( `/admin/reservations?fields=%2binventory_item.*`, diff --git a/packages/medusa/src/api/admin/reservations/validators.ts b/packages/medusa/src/api/admin/reservations/validators.ts index c65c512780..72eb20f95d 100644 --- a/packages/medusa/src/api/admin/reservations/validators.ts +++ b/packages/medusa/src/api/admin/reservations/validators.ts @@ -18,6 +18,7 @@ export const AdminGetReservationsParams = createFindParams({ offset: 0, }).merge( z.object({ + q: z.string().optional(), location_id: z.union([z.string(), z.array(z.string())]).optional(), inventory_item_id: z.union([z.string(), z.array(z.string())]).optional(), line_item_id: z.union([z.string(), z.array(z.string())]).optional(), diff --git a/packages/modules/inventory/src/models/reservation-item.ts b/packages/modules/inventory/src/models/reservation-item.ts index 37a2d2504b..a4646e52bb 100644 --- a/packages/modules/inventory/src/models/reservation-item.ts +++ b/packages/modules/inventory/src/models/reservation-item.ts @@ -14,6 +14,7 @@ import { BigNumber, DALUtils, MikroOrmBigNumberProperty, + Searchable, createPsqlIndexStatementHelper, generateEntityId, } from "@medusajs/framework/utils" @@ -87,6 +88,7 @@ export class ReservationItem { @Property({ type: "text", nullable: true }) external_id: string | null = null + @Searchable() @Property({ type: "text", nullable: true }) description: string | null = null @@ -105,6 +107,7 @@ export class ReservationItem { }) inventory_item_id: string + @Searchable() @ManyToOne(() => InventoryItem, { persist: false, })