ChannelService

ChannelService

Contains methods relating to Channel entities.

Signature

class ChannelService {
  constructor(connection: TransactionalConnection, configService: ConfigService, globalSettingsService: GlobalSettingsService, customFieldRelationService: CustomFieldRelationService)
  async assignToCurrentChannel(entity: T, ctx: RequestContext) => Promise<T>;
  async assignToChannels(ctx: RequestContext, entityType: Type<T>, entityId: ID, channelIds: ID[]) => Promise<T>;
  async removeFromChannels(ctx: RequestContext, entityType: Type<T>, entityId: ID, channelIds: ID[]) => Promise<T | undefined>;
  async getChannelFromToken(token: string) => Promise<Channel>;
  async getDefaultChannel() => Promise<Channel>;
  findAll(ctx: RequestContext) => Promise<Channel[]>;
  findOne(ctx: RequestContext, id: ID) => Promise<Channel | undefined>;
  async create(ctx: RequestContext, input: CreateChannelInput) => Promise<ErrorResultUnion<CreateChannelResult, Channel>>;
  async update(ctx: RequestContext, input: UpdateChannelInput) => Promise<ErrorResultUnion<UpdateChannelResult, Channel>>;
  async delete(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
  public isChannelAware(entity: VendureEntity) => entity is VendureEntity & ChannelAware;
}

Members

constructor

method
type:
(connection: TransactionalConnection, configService: ConfigService, globalSettingsService: GlobalSettingsService, customFieldRelationService: CustomFieldRelationService) => ChannelService

assignToCurrentChannel

async method
type:
(entity: T, ctx: RequestContext) => Promise<T>
Assigns a ChannelAware entity to the default Channel as well as any channel specified in the RequestContext.

assignToChannels

async method
type:
(ctx: RequestContext, entityType: Type<T>, entityId: ID, channelIds: ID[]) => Promise<T>
Assigns the entity to the given Channels and saves.

removeFromChannels

async method
type:
(ctx: RequestContext, entityType: Type<T>, entityId: ID, channelIds: ID[]) => Promise<T | undefined>
Removes the entity from the given Channels and saves.

getChannelFromToken

async method
type:
(token: string) => Promise<Channel>
Given a channel token, returns the corresponding Channel if it exists, else will throw a ChannelNotFoundError.

getDefaultChannel

async method
type:
() => Promise<Channel>
Returns the default Channel.

findAll

method
type:
(ctx: RequestContext) => Promise<Channel[]>

findOne

method
type:
(ctx: RequestContext, id: ID) => Promise<Channel | undefined>

create

async method
type:
(ctx: RequestContext, input: CreateChannelInput) => Promise<ErrorResultUnion<CreateChannelResult, Channel>>

update

async method
type:
(ctx: RequestContext, input: UpdateChannelInput) => Promise<ErrorResultUnion<UpdateChannelResult, Channel>>

delete

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

isChannelAware

public method
type:
(entity: VendureEntity) => entity is VendureEntity & ChannelAware
Type guard method which returns true if the given entity is an instance of a class which implements the ChannelAware interface.