fix: allow passing idempotency key to service layer create (#2701)

**What**

Allow DraftOrders to be created with an IdempotencyKey. 

Note this doesn't implement idempotency for the DraftOrder create endpoint but allows the service layer to ingest the key and store it in the database. This is a preliminary step to being able to support an idempotent API request.
This commit is contained in:
Sebastian Rindom
2022-11-30 10:23:59 +01:00
committed by GitHub
parent 0764c6f994
commit 198fe78c13
3 changed files with 14 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): allow passing idempotency key to service layer create

View File

@@ -259,8 +259,13 @@ class DraftOrderService extends TransactionBaseService {
)
}
const { shipping_methods, no_notification_order, items, ...rawCart } =
data
const {
shipping_methods,
no_notification_order,
items,
idempotency_key,
...rawCart
} = data
const cartServiceTx =
this.cartService_.withTransaction(transactionManager)
@@ -285,6 +290,7 @@ class DraftOrderService extends TransactionBaseService {
const draftOrder = draftOrderRepo.create({
cart_id: createdCart.id,
no_notification_order,
idempotency_key,
})
const result = await draftOrderRepo.save(draftOrder)

View File

@@ -16,6 +16,7 @@ export type DraftOrderCreateProps = {
no_notification_order?: boolean
shipping_methods: ShippingMethod[]
metadata?: Record<string, unknown>
idempotency_key?: string
}
type ShippingMethod = {