Files
medusa-store/docs/content/references/services/classes/InventoryService.md
Shahed Nasser 02d5c1da88 docs: update Typedoc and regenerate references (#1994)
* generated new services reference

* changed from automatic push to automated pull request

* updated typedoc, regenerated JS Client reference

* regenerated the reference after updating typedoc

* added action for js client
2022-08-04 17:29:52 +03:00

5.8 KiB

Class: InventoryService

Hierarchy

Constructors

constructor

new InventoryService(__namedParameters)

Parameters

Name Type
__namedParameters InventoryServiceProps

Overrides

TransactionBaseService<InventoryService&gt;.constructor

Defined in

packages/medusa/src/services/inventory.ts:18

Properties

configModule

Protected Optional Readonly configModule: Record<string, unknown>

Inherited from

TransactionBaseService.configModule

Defined in

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


container

Protected Readonly container: unknown

Inherited from

TransactionBaseService.container

Defined in

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


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/inventory.ts:15


productVariantService_

Protected Readonly productVariantService_: ProductVariantService

Defined in

packages/medusa/src/services/inventory.ts:13


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/inventory.ts:16

Methods

adjustInventory

adjustInventory(variantId, adjustment): Promise<undefined | ProductVariant>

Updates the inventory of a variant based on a given adjustment.

Parameters

Name Type Description
variantId string the id of the variant to update
adjustment number the number to adjust the inventory quantity by

Returns

Promise<undefined | ProductVariant>

resolves to the update result.

Defined in

packages/medusa/src/services/inventory.ts:31


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

Name Type Description
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:53


confirmInventory

confirmInventory(variantId, quantity): Promise<boolean>

Checks if the inventory of a variant can cover a given quantity. Will return true if the variant doesn't have managed inventory or if the variant allows backorders or if the inventory quantity is greater than quantity.

Parameters

Name Type Description
variantId undefined | null | string the id of the variant to check
quantity number the number of units to check availability for

Returns

Promise<boolean>

true if the inventory covers the quantity

Defined in

packages/medusa/src/services/inventory.ts:63


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

Name Type
err Record<string, unknown> | { code: string }

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

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


withTransaction

withTransaction(transactionManager?): InventoryService

Parameters

Name Type
transactionManager? EntityManager

Returns

InventoryService

Inherited from

TransactionBaseService.withTransaction

Defined in

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