Class: ProductCategoryService
Provides layer to manipulate product categories.
Hierarchy
TransactionBaseService↳
ProductCategoryService
Constructors
constructor
• new ProductCategoryService(__namedParameters)
Parameters
| Name | Type |
|---|---|
__namedParameters | InjectedDependencies |
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/product-category.ts:40
Properties
__configModule__
• Protected Optional Readonly __configModule__: Record<string, unknown>
Inherited from
TransactionBaseService.__configModule__
Defined in
medusa/src/interfaces/transaction-base-service.ts:14
__container__
• Protected Readonly __container__: any
Inherited from
TransactionBaseService.__container__
Defined in
medusa/src/interfaces/transaction-base-service.ts:13
__moduleDeclaration__
• Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
medusa/src/interfaces/transaction-base-service.ts:15
eventBusService_
• Protected Readonly eventBusService_: EventBusService
Defined in
medusa/src/services/product-category.ts:32
manager_
• Protected manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:5
productCategoryRepo_
• Protected Readonly productCategoryRepo_: TreeRepository<ProductCategory> & { addProducts: (productCategoryId: string, productIds: string[]) => Promise<void> ; findOneWithDescendants: (query: FindOneOptions<ProductCategory>, treeScope: QuerySelector<ProductCategory>) => Promise<null | ProductCategory> ; getFreeTextSearchResultsAndCount: (options: ExtendedFindConfig<ProductCategory>, q?: string, treeScope: QuerySelector<ProductCategory>, includeTree: boolean) => Promise<[ProductCategory[], number]> ; removeProducts: (productCategoryId: string, productIds: string[]) => Promise<DeleteResult> }
Defined in
medusa/src/services/product-category.ts:31
transactionManager_
• Protected transactionManager_: undefined | EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:6
Events
▪ Static Events: Object
Type declaration
| Name | Type |
|---|---|
CREATED | string |
DELETED | string |
UPDATED | string |
Defined in
medusa/src/services/product-category.ts:34
Accessors
activeManager_
• Protected get activeManager_(): EntityManager
Returns
EntityManager
Inherited from
TransactionBaseService.activeManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:8
Methods
addProducts
▸ addProducts(productCategoryId, productIds): Promise<void>
Add a batch of product to a product category
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryId | string | The id of the product category on which to add the products |
productIds | string[] | The products ids to attach to the product category |
Returns
Promise<void>
the product category on which the products have been added
Defined in
medusa/src/services/product-category.ts:314
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
medusa/src/interfaces/transaction-base-service.ts:56
create
▸ create(productCategoryInput): Promise<ProductCategory>
Creates a product category
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryInput | CreateProductCategoryInput | parameters to create a product category |
Returns
Promise<ProductCategory>
created product category
Defined in
medusa/src/services/product-category.ts:187
delete
▸ delete(productCategoryId): Promise<void>
Deletes a product category
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryId | string | is the id of the product category to delete |
Returns
Promise<void>
a promise
Defined in
medusa/src/services/product-category.ts:268
fetchReorderConditions
▸ Protected fetchReorderConditions(productCategory, input, shouldDeleteElement?): ReorderConditions
Parameters
| Name | Type | Default value |
|---|---|---|
productCategory | ProductCategory | undefined |
input | UpdateProductCategoryInput | undefined |
shouldDeleteElement | boolean | false |
Returns
ReorderConditions
Defined in
medusa/src/services/product-category.ts:349
listAndCount
▸ listAndCount(selector, config?, treeSelector?): Promise<[ProductCategory[], number]>
Lists product category based on the provided parameters and includes the count of product category that match the query.
Parameters
| Name | Type | Description |
|---|---|---|
selector | TreeQuerySelector<ProductCategory> | Filter options for product category. |
config | FindConfig<ProductCategory> | Configuration for query. |
treeSelector | QuerySelector<ProductCategory> | Filter options for product category tree relations |
Returns
Promise<[ProductCategory[], number]>
an array containing the product category as the first element and the total count of product category that matches the query as the second element.
Defined in
medusa/src/services/product-category.ts:61
performReordering
▸ Protected performReordering(repository, conditions): Promise<void>
Parameters
| Name | Type |
|---|---|
repository | TreeRepository<ProductCategory> & { addProducts: (productCategoryId: string, productIds: string[]) => Promise<void> ; findOneWithDescendants: (query: FindOneOptions<ProductCategory>, treeScope: QuerySelector<ProductCategory>) => Promise<null | ProductCategory> ; getFreeTextSearchResultsAndCount: (options: ExtendedFindConfig<ProductCategory>, q?: string, treeScope: QuerySelector<ProductCategory>, includeTree: boolean) => Promise<[ProductCategory[], number]> ; removeProducts: (productCategoryId: string, productIds: string[]) => Promise<DeleteResult> } |
conditions | ReorderConditions |
Returns
Promise<void>
Defined in
medusa/src/services/product-category.ts:377
removeProducts
▸ removeProducts(productCategoryId, productIds): Promise<void>
Remove a batch of product from a product category
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryId | string | The id of the product category on which to remove the products |
productIds | string[] | The products ids to remove from the product category |
Returns
Promise<void>
the product category on which the products have been removed
Defined in
medusa/src/services/product-category.ts:333
retrieve
▸ retrieve(productCategoryId, config?, selector?, treeSelector?): Promise<ProductCategory>
Retrieves a product category by id.
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryId | string | the id of the product category to retrieve. |
config | FindConfig<ProductCategory> | the config of the product category to retrieve. |
selector | Selector<ProductCategory> | |
treeSelector | QuerySelector<ProductCategory> |
Returns
Promise<ProductCategory>
the product category.
Defined in
medusa/src/services/product-category.ts:139
retrieveByHandle
▸ retrieveByHandle(handle, config?, selector?, treeSelector?): Promise<ProductCategory>
Retrieves a product category by handle.
Parameters
| Name | Type | Description |
|---|---|---|
handle | string | the handle of the category |
config | FindConfig<ProductCategory> | the config of the product category to retrieve. |
selector | Selector<ProductCategory> | |
treeSelector | QuerySelector<ProductCategory> |
Returns
Promise<ProductCategory>
the product category.
Defined in
medusa/src/services/product-category.ts:165
retrieve_
▸ Protected retrieve_(config?, selector?, treeSelector?): Promise<ProductCategory>
A generic retrieve for fining product categories by different attributes.
Parameters
| Name | Type | Description |
|---|---|---|
config | FindConfig<ProductCategory> | the config of the product category to retrieve. |
selector | Selector<ProductCategory> | |
treeSelector | QuerySelector<ProductCategory> |
Returns
Promise<ProductCategory>
the product category.
Defined in
medusa/src/services/product-category.ts:102
shiftSiblings
▸ Protected shiftSiblings(repository, conditions): Promise<void>
Parameters
| Name | Type |
|---|---|
repository | TreeRepository<ProductCategory> & { addProducts: (productCategoryId: string, productIds: string[]) => Promise<void> ; findOneWithDescendants: (query: FindOneOptions<ProductCategory>, treeScope: QuerySelector<ProductCategory>) => Promise<null | ProductCategory> ; getFreeTextSearchResultsAndCount: (options: ExtendedFindConfig<ProductCategory>, q?: string, treeScope: QuerySelector<ProductCategory>, includeTree: boolean) => Promise<[ProductCategory[], number]> ; removeProducts: (productCategoryId: string, productIds: string[]) => Promise<DeleteResult> } |
conditions | ReorderConditions |
Returns
Promise<void>
Defined in
medusa/src/services/product-category.ts:415
shouldRetryTransaction_
▸ Protected shouldRetryTransaction_(err): boolean
Parameters
| Name | Type |
|---|---|
err | Record<string, unknown> | { code: string } |
Returns
boolean
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
transformParentIdToEntity
▸ Protected transformParentIdToEntity(productCategoryInput): Promise<CreateProductCategoryInput | UpdateProductCategoryInput>
Accepts an input object and transforms product_category_id into product_category entity.
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryInput | CreateProductCategoryInput | UpdateProductCategoryInput | params used to create/update |
Returns
Promise<CreateProductCategoryInput | UpdateProductCategoryInput>
transformed productCategoryInput
Defined in
medusa/src/services/product-category.ts:513
update
▸ update(productCategoryId, productCategoryInput): Promise<ProductCategory>
Updates a product category
Parameters
| Name | Type | Description |
|---|---|---|
productCategoryId | string | id of product category to update |
productCategoryInput | UpdateProductCategoryInput | parameters to update in product category |
Returns
Promise<ProductCategory>
updated product category
Defined in
medusa/src/services/product-category.ts:221
withTransaction
▸ withTransaction(transactionManager?): ProductCategoryService
Parameters
| Name | Type |
|---|---|
transactionManager? | EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction