AssetService

AssetService

Contains methods relating to Asset entities.

Signature

class AssetService {
  constructor(connection: TransactionalConnection, configService: ConfigService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus, tagService: TagService, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService)
  findOne(ctx: RequestContext, id: ID, relations?: RelationPaths<Asset>) => Promise<Asset | undefined>;
  findAll(ctx: RequestContext, options?: AssetListOptions, relations?: RelationPaths<Asset>) => Promise<PaginatedList<Asset>>;
  async getFeaturedAsset(ctx: RequestContext, entity: T) => Promise<Asset | undefined>;
  async getEntityAssets(ctx: RequestContext, entity: T) => Promise<Asset[] | undefined>;
  async updateFeaturedAsset(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>;
  async updateEntityAssets(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>;
  async create(ctx: RequestContext, input: CreateAssetInput) => Promise<CreateAssetResult>;
  async update(ctx: RequestContext, input: UpdateAssetInput) => Promise<Asset>;
  async delete(ctx: RequestContext, ids: ID[], force: boolean = false, deleteFromAllChannels: boolean = false) => Promise<DeletionResponse>;
  async assignToChannel(ctx: RequestContext, input: AssignAssetsToChannelInput) => Promise<Asset[]>;
  async createFromFileStream(stream: ReadStream, ctx?: RequestContext) => Promise<CreateAssetResult>;
  async createFromFileStream(stream: Readable, filePath: string) => Promise<CreateAssetResult>;
  async createFromFileStream(stream: ReadStream | Readable, maybeFilePathOrCtx?: string | RequestContext) => Promise<CreateAssetResult>;
}

Members

constructor

method
type:
(connection: TransactionalConnection, configService: ConfigService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus, tagService: TagService, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService) => AssetService

findOne

method
type:
(ctx: RequestContext, id: ID, relations?: RelationPaths<Asset>) => Promise<Asset | undefined>

findAll

method
type:
(ctx: RequestContext, options?: AssetListOptions, relations?: RelationPaths<Asset>) => Promise<PaginatedList<Asset>>

getFeaturedAsset

async method
type:
(ctx: RequestContext, entity: T) => Promise<Asset | undefined>

getEntityAssets

async method
type:
(ctx: RequestContext, entity: T) => Promise<Asset[] | undefined>
Returns the Assets of an entity which has a well-ordered list of Assets, such as Product, ProductVariant or Collection.

updateFeaturedAsset

async method
type:
(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>

updateEntityAssets

async method
type:
(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>
Updates the assets / featuredAsset of an entity, ensuring that only valid assetIds are used.

create

async method
type:
(ctx: RequestContext, input: CreateAssetInput) => Promise<CreateAssetResult>

Create an Asset based on a file uploaded via the GraphQL API. The file should be uploaded using the GraphQL multipart request specification, e.g. using the apollo-upload-client npm package.

See the Uploading Files docs for an example of usage.

update

async method
type:
(ctx: RequestContext, input: UpdateAssetInput) => Promise<Asset>
Updates the name, focalPoint, tags & custom fields of an Asset.

delete

async method
type:
(ctx: RequestContext, ids: ID[], force: boolean = false, deleteFromAllChannels: boolean = false) => Promise<DeletionResponse>
Deletes an Asset after performing checks to ensure that the Asset is not currently in use by a Product, ProductVariant or Collection.

assignToChannel

async method
type:
(ctx: RequestContext, input: AssignAssetsToChannelInput) => Promise<Asset[]>

createFromFileStream

async method
type:
(stream: ReadStream, ctx?: RequestContext) => Promise<CreateAssetResult>
Create an Asset from a file stream, for example to create an Asset during data import.

createFromFileStream

async method
type:
(stream: Readable, filePath: string) => Promise<CreateAssetResult>

createFromFileStream

async method
type:
(stream: ReadStream | Readable, maybeFilePathOrCtx?: string | RequestContext) => Promise<CreateAssetResult>

EntityWithAssets

Certain entities (Product, ProductVariant, Collection) use this interface to model a featured asset and then a list of assets with a defined order.

Signature

interface EntityWithAssets extends VendureEntity {
  featuredAsset: Asset | null;
  assets: OrderableAsset[];
}

Extends

Members

featuredAsset

property
type:
Asset | null

assets

property
type:
OrderableAsset[]

EntityAssetInput

Used when updating entities which implement EntityWithAssets.

Signature

interface EntityAssetInput {
  assetIds?: ID[] | null;
  featuredAssetId?: ID | null;
}

Members

assetIds

property
type:
ID[] | null

featuredAssetId

property
type:
ID | null