Skip to main content

Class: ProductCategoryService

Provides layer to manipulate product categories.

Hierarchy

  • TransactionBaseService

    ProductCategoryService

Constructors

constructor

new ProductCategoryService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

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

NameType
CREATEDstring
DELETEDstring
UPDATEDstring

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

NameTypeDescription
productCategoryIdstringThe id of the product category on which to add the products
productIdsstring[]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

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

medusa/src/interfaces/transaction-base-service.ts:56


create

create(productCategoryInput): Promise<ProductCategory>

Creates a product category

Parameters

NameTypeDescription
productCategoryInputCreateProductCategoryInputparameters 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

NameTypeDescription
productCategoryIdstringis 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

NameTypeDefault value
productCategoryProductCategoryundefined
inputUpdateProductCategoryInputundefined
shouldDeleteElementbooleanfalse

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

NameTypeDescription
selectorTreeQuerySelector<ProductCategory>Filter options for product category.
configFindConfig<ProductCategory>Configuration for query.
treeSelectorQuerySelector<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

NameType
repositoryTreeRepository<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> }
conditionsReorderConditions

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

NameTypeDescription
productCategoryIdstringThe id of the product category on which to remove the products
productIdsstring[]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

NameTypeDescription
productCategoryIdstringthe id of the product category to retrieve.
configFindConfig<ProductCategory>the config of the product category to retrieve.
selectorSelector<ProductCategory>
treeSelectorQuerySelector<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

NameTypeDescription
handlestringthe handle of the category
configFindConfig<ProductCategory>the config of the product category to retrieve.
selectorSelector<ProductCategory>
treeSelectorQuerySelector<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

NameTypeDescription
configFindConfig<ProductCategory>the config of the product category to retrieve.
selectorSelector<ProductCategory>
treeSelectorQuerySelector<ProductCategory>

Returns

Promise<ProductCategory>

the product category.

Defined in

medusa/src/services/product-category.ts:102


shiftSiblings

Protected shiftSiblings(repository, conditions): Promise<void>

Parameters

NameType
repositoryTreeRepository<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> }
conditionsReorderConditions

Returns

Promise<void>

Defined in

medusa/src/services/product-category.ts:415


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

NameType
errRecord<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

NameTypeDescription
productCategoryInputCreateProductCategoryInput | UpdateProductCategoryInputparams 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

NameTypeDescription
productCategoryIdstringid of product category to update
productCategoryInputUpdateProductCategoryInputparameters 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

NameType
transactionManager?EntityManager

Returns

ProductCategoryService

Inherited from

TransactionBaseService.withTransaction

Defined in

medusa/src/interfaces/transaction-base-service.ts:20

Was this page helpful?