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 authored and GitHub committed 2022-11-30 09:23:59 +00:00
1 parent 0764c6f994
commit 198fe78c13
3 files changed
+14 -2

No files matched your search

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