CollectionService

CollectionService

Contains methods relating to Collection entities.

Signature

class CollectionService implements OnModuleInit {
  constructor(connection: TransactionalConnection, channelService: ChannelService, assetService: AssetService, facetValueService: FacetValueService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, jobQueueService: JobQueueService, configService: ConfigService, slugValidator: SlugValidator, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService)
  async findAll(ctx: RequestContext, options?: ListQueryOptions<Collection>) => Promise<PaginatedList<Translated<Collection>>>;
  async findOne(ctx: RequestContext, collectionId: ID) => Promise<Translated<Collection> | undefined>;
  async findByIds(ctx: RequestContext, ids: ID[]) => Promise<Array<Translated<Collection>>>;
  async findOneBySlug(ctx: RequestContext, slug: string) => Promise<Translated<Collection> | undefined>;
  getAvailableFilters(ctx: RequestContext) => ConfigurableOperationDefinition[];
  async getParent(ctx: RequestContext, collectionId: ID) => Promise<Collection | undefined>;
  async getChildren(ctx: RequestContext, collectionId: ID) => Promise<Collection[]>;
  async getBreadcrumbs(ctx: RequestContext, collection: Collection) => Promise<Array<{ name: string; id: ID }>>;
  async getCollectionsByProductId(ctx: RequestContext, productId: ID, publicOnly: boolean) => Promise<Array<Translated<Collection>>>;
  async getDescendants(ctx: RequestContext, rootId: ID, maxDepth: number = Number.MAX_SAFE_INTEGER) => Promise<Array<Translated<Collection>>>;
  getAncestors(collectionId: ID) => Promise<Collection[]>;
  getAncestors(collectionId: ID, ctx: RequestContext) => Promise<Array<Translated<Collection>>>;
  async getAncestors(collectionId: ID, ctx?: RequestContext) => Promise<Array<Translated<Collection> | Collection>>;
  async create(ctx: RequestContext, input: CreateCollectionInput) => Promise<Translated<Collection>>;
  async update(ctx: RequestContext, input: UpdateCollectionInput) => Promise<Translated<Collection>>;
  async delete(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
  async move(ctx: RequestContext, input: MoveCollectionInput) => Promise<Translated<Collection>>;
  async getCollectionProductVariantIds(collection: Collection, ctx?: RequestContext) => Promise<ID[]>;
}

Implements

  • OnModuleInit

Members

constructor

method
type:
(connection: TransactionalConnection, channelService: ChannelService, assetService: AssetService, facetValueService: FacetValueService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, jobQueueService: JobQueueService, configService: ConfigService, slugValidator: SlugValidator, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService) => CollectionService

findAll

async method
type:
(ctx: RequestContext, options?: ListQueryOptions<Collection>) => Promise<PaginatedList<Translated<Collection>>>

findOne

async method
type:
(ctx: RequestContext, collectionId: ID) => Promise<Translated<Collection> | undefined>

findByIds

async method
type:
(ctx: RequestContext, ids: ID[]) => Promise<Array<Translated<Collection>>>

findOneBySlug

async method
type:
(ctx: RequestContext, slug: string) => Promise<Translated<Collection> | undefined>

getAvailableFilters

method
type:
(ctx: RequestContext) => ConfigurableOperationDefinition[]
Returns all configured CollectionFilters, as specified by the CatalogOptions.

getParent

async method
type:
(ctx: RequestContext, collectionId: ID) => Promise<Collection | undefined>

getChildren

async method
type:
(ctx: RequestContext, collectionId: ID) => Promise<Collection[]>
Returns all child Collections of the Collection with the given id.

getBreadcrumbs

async method
type:
(ctx: RequestContext, collection: Collection) => Promise<Array<{ name: string; id: ID }>>
Returns an array of name/id pairs representing all ancestor Collections up to the Root Collection.

getCollectionsByProductId

async method
type:
(ctx: RequestContext, productId: ID, publicOnly: boolean) => Promise<Array<Translated<Collection>>>
Returns all Collections which are associated with the given Product ID.

getDescendants

async method
type:
(ctx: RequestContext, rootId: ID, maxDepth: number = Number.MAX_SAFE_INTEGER) => Promise<Array<Translated<Collection>>>
Returns the descendants of a Collection as a flat array. The depth of the traversal can be limited with the maxDepth argument. So to get only the immediate children, set maxDepth = 1.

getAncestors

method
type:
(collectionId: ID) => Promise<Collection[]>
Gets the ancestors of a given collection. Note that since ProductCategories are implemented as an adjacency list, this method will produce more queries the deeper the collection is in the tree.

getAncestors

method
type:
(collectionId: ID, ctx: RequestContext) => Promise<Array<Translated<Collection>>>

getAncestors

async method
type:
(collectionId: ID, ctx?: RequestContext) => Promise<Array<Translated<Collection> | Collection>>

create

async method
type:
(ctx: RequestContext, input: CreateCollectionInput) => Promise<Translated<Collection>>

update

async method
type:
(ctx: RequestContext, input: UpdateCollectionInput) => Promise<Translated<Collection>>

delete

async method
type:
(ctx: RequestContext, id: ID) => Promise<DeletionResponse>

move

async method
type:
(ctx: RequestContext, input: MoveCollectionInput) => Promise<Translated<Collection>>
Moves a Collection by specifying the parent Collection ID, and an index representing the order amongst its siblings.

getCollectionProductVariantIds

async method
type:
(collection: Collection, ctx?: RequestContext) => Promise<ID[]>