feat(medusa): Allow creating DraftOrders without items (#2719)
This commit is contained in:
1 parent
d8893d6b9f
commit
3113d8024f
6 files changed
+35
-18
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa): Create draft orders without items
|
||||||
@@ -381,6 +381,30 @@ describe("/admin/draft-orders", () => {
|
|||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("creates a draft order without a single item", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
email: "oli@test.dk",
|
||||||
|
shipping_address: "oli-shipping",
|
||||||
|
region_id: "test-region",
|
||||||
|
customer_id: "oli-test",
|
||||||
|
shipping_methods: [
|
||||||
|
{
|
||||||
|
option_id: "test-option",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/draft-orders",
|
||||||
|
payload,
|
||||||
|
adminReqConfig
|
||||||
|
)
|
||||||
|
expect(response.data.draft_order.cart.items).toEqual([])
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
})
|
||||||
|
|
||||||
it("creates a draft order with product variant with custom price and custom item price set to 0", async () => {
|
it("creates a draft order with product variant with custom price and custom item price set to 0", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import { IsType } from "../../../../utils/validators/is-type"
|
|||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - email
|
* - email
|
||||||
* - items
|
|
||||||
* - region_id
|
* - region_id
|
||||||
* - shipping_methods
|
* - shipping_methods
|
||||||
* properties:
|
* properties:
|
||||||
@@ -270,7 +269,8 @@ export class AdminPostDraftOrdersReq {
|
|||||||
@Type(() => Item)
|
@Type(() => Item)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
items: Item[]
|
@IsOptional()
|
||||||
|
items?: Item[]
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
region_id: string
|
region_id: string
|
||||||
|
|||||||
@@ -209,17 +209,12 @@ describe("DraftOrderService", () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it("fails on missing items", async () => {
|
it("creating a draft order without items is allowed", async () => {
|
||||||
try {
|
|
||||||
await draftOrderService.create({
|
await draftOrderService.create({
|
||||||
region_id: "test-region",
|
region_id: "test-region",
|
||||||
items: [],
|
items: [],
|
||||||
|
shipping_methods: []
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
expect(error.message).toEqual(
|
|
||||||
`Items are required to create a draft order`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -259,13 +259,6 @@ class DraftOrderService extends TransactionBaseService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.items || !data.items.length) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.INVALID_DATA,
|
|
||||||
`Items are required to create a draft order`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
shipping_methods,
|
shipping_methods,
|
||||||
no_notification_order,
|
no_notification_order,
|
||||||
@@ -310,7 +303,7 @@ class DraftOrderService extends TransactionBaseService {
|
|||||||
const lineItemServiceTx =
|
const lineItemServiceTx =
|
||||||
this.lineItemService_.withTransaction(transactionManager)
|
this.lineItemService_.withTransaction(transactionManager)
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of (items || [])) {
|
||||||
if (item.variant_id) {
|
if (item.variant_id) {
|
||||||
const line = await lineItemServiceTx.generate(
|
const line = await lineItemServiceTx.generate(
|
||||||
item.variant_id,
|
item.variant_id,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export type DraftOrderCreateProps = {
|
|||||||
billing_address?: Partial<AddressPayload>
|
billing_address?: Partial<AddressPayload>
|
||||||
shipping_address_id?: string
|
shipping_address_id?: string
|
||||||
shipping_address?: Partial<AddressPayload>
|
shipping_address?: Partial<AddressPayload>
|
||||||
items: Item[]
|
items?: Item[]
|
||||||
region_id: string
|
region_id: string
|
||||||
discounts?: Discount[]
|
discounts?: Discount[]
|
||||||
customer_id?: string
|
customer_id?: string
|
||||||
|
|||||||
Reference in new issue
Block a user