Skip to main content

Class: DraftOrderService

Handles draft orders

Implements

Hierarchy

  • TransactionBaseService

    DraftOrderService

Constructors

constructor

new DraftOrderService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/draft-order.ts:54

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


cartService_

Protected Readonly cartService_: CartService

Defined in

packages/medusa/src/services/draft-order.ts:48


customShippingOptionService_

Protected Readonly customShippingOptionService_: CustomShippingOptionService

Defined in

packages/medusa/src/services/draft-order.ts:52


draftOrderRepository_

Protected Readonly draftOrderRepository_: typeof DraftOrderRepository

Defined in

packages/medusa/src/services/draft-order.ts:44


eventBus_

Protected Readonly eventBus_: EventBusService

Defined in

packages/medusa/src/services/draft-order.ts:47


lineItemService_

Protected Readonly lineItemService_: LineItemService

Defined in

packages/medusa/src/services/draft-order.ts:49


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/draft-order.ts:41


orderRepository_

Protected Readonly orderRepository_: typeof OrderRepository

Defined in

packages/medusa/src/services/draft-order.ts:46


paymentRepository_

Protected Readonly paymentRepository_: typeof PaymentRepository

Defined in

packages/medusa/src/services/draft-order.ts:45


productVariantService_

Protected Readonly productVariantService_: ProductVariantService

Defined in

packages/medusa/src/services/draft-order.ts:50


shippingOptionService_

Protected Readonly shippingOptionService_: ShippingOptionService

Defined in

packages/medusa/src/services/draft-order.ts:51


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/draft-order.ts:42


Events

Static Readonly Events: Object

Type declaration

NameType
CREATEDstring
UPDATEDstring

Defined in

packages/medusa/src/services/draft-order.ts:36

Methods

atomicPhase_

Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type parameters

Name
TResult
TError

Parameters

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (error: TError) => Promise<void | TResult>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?(error: TError) => Promise<void | TResult>Potential error handler

Returns

Promise<TResult>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:50


create

create(data): Promise<DraftOrder>

Creates a draft order.

Parameters

NameTypeDescription
dataDraftOrderCreatePropsdata to create draft order from

Returns

Promise<DraftOrder>

the created draft order

Defined in

packages/medusa/src/services/draft-order.ts:248


delete

delete(draftOrderId): Promise<undefined | DraftOrder>

Deletes draft order idempotently.

Parameters

NameTypeDescription
draftOrderIdstringid of draft order to delete

Returns

Promise<undefined | DraftOrder>

empty promise

Defined in

packages/medusa/src/services/draft-order.ts:147


list

list(selector, config?): Promise<DraftOrder[]>

Lists draft orders

Parameters

NameTypeDescription
selectoranyquery object for find
configFindConfig<DraftOrder>configurable attributes for find

Returns

Promise<DraftOrder[]>

list of draft orders

Defined in

packages/medusa/src/services/draft-order.ts:225


listAndCount

listAndCount(selector, config?): Promise<[DraftOrder[], number]>

Lists draft orders alongside the count

Parameters

NameTypeDescription
selectoranyquery selector to filter draft orders
configFindConfig<DraftOrder>query config

Returns

Promise<[DraftOrder[], number]>

draft orders

Defined in

packages/medusa/src/services/draft-order.ts:171


registerCartCompletion

registerCartCompletion(draftOrderId, orderId): Promise<UpdateResult>

Registers a draft order as completed, when an order has been completed.

Parameters

NameTypeDescription
draftOrderIdstringid of draft order to complete
orderIdstringid of order completed from draft order cart

Returns

Promise<UpdateResult>

the created order

Defined in

packages/medusa/src/services/draft-order.ts:365


retrieve

retrieve(draftOrderId, config?): Promise<DraftOrder>

Retrieves a draft order with the given id.

Parameters

NameTypeDescription
draftOrderIdstringid of the draft order to retrieve
configFindConfig<DraftOrder>query object for findOne

Returns

Promise<DraftOrder>

the draft order

Defined in

packages/medusa/src/services/draft-order.ts:87


retrieveByCartId

retrieveByCartId(cartId, config?): Promise<DraftOrder>

Retrieves a draft order based on its associated cart id

Parameters

NameTypeDescription
cartIdstringcart id that the draft orders's cart has
configFindConfig<DraftOrder>query object for findOne

Returns

Promise<DraftOrder>

the draft order

Defined in

packages/medusa/src/services/draft-order.ts:121


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

NameType
errRecord<string, unknown> | { code: string }

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(id, data): Promise<DraftOrder>

Updates a draft order with the given data

Parameters

NameTypeDescription
idstringid of the draft order
dataObjectvalues to update the order with
data.no_notification_orderboolean-

Returns

Promise<DraftOrder>

the updated draft order

Defined in

packages/medusa/src/services/draft-order.ts:394


withTransaction

withTransaction(transactionManager?): DraftOrderService

Parameters

NameType
transactionManager?EntityManager

Returns

DraftOrderService

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14