Skip to main content

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>>;
getFeaturedAsset(ctx: RequestContext, entity: T) => Promise<Asset | undefined>;
getEntityAssets(ctx: RequestContext, entity: T) => Promise<Asset[] | undefined>;
updateFeaturedAsset(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>;
updateEntityAssets(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>;
create(ctx: RequestContext, input: CreateAssetInput) => Promise<CreateAssetResult>;
update(ctx: RequestContext, input: UpdateAssetInput) => Promise<Asset>;
delete(ctx: RequestContext, ids: ID[], force: boolean = false, deleteFromAllChannels: boolean = false) => Promise<DeletionResponse>;
assignToChannel(ctx: RequestContext, input: AssignAssetsToChannelInput) => Promise<Asset[]>;
createFromFileStream(stream: ReadStream, ctx?: RequestContext) => Promise<CreateAssetResult>;
createFromFileStream(stream: Readable, filePath: string, ctx?: RequestContext) => Promise<CreateAssetResult>;
createFromFileStream(stream: ReadStream | Readable, maybeFilePathOrCtx?: string | RequestContext, maybeCtx?: RequestContext) => Promise<CreateAssetResult>;
}

constructor

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

findOne

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

findAll

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

getFeaturedAsset

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

getEntityAssets

method
(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

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

updateEntityAssets

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

Updates the assets / featuredAsset of an entity, ensuring that only valid assetIds are used.

create

method
(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

method
(ctx: RequestContext, input: UpdateAssetInput) => Promise<Asset>

Updates the name, focalPoint, tags & custom fields of an Asset.

delete

method
(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

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

createFromFileStream

method
(stream: ReadStream, ctx?: RequestContext) => Promise<CreateAssetResult>

Create an Asset from a file stream, for example to create an Asset during data import.

createFromFileStream

method
(stream: Readable, filePath: string, ctx?: RequestContext) => Promise<CreateAssetResult>

createFromFileStream

method
(stream: ReadStream | Readable, maybeFilePathOrCtx?: string | RequestContext, maybeCtx?: 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[];
}

featuredAsset

property
Asset | null

assets

property

EntityAssetInput

Used when updating entities which implement EntityWithAssets.

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

assetIds

property
ID[] | null

featuredAssetId

property
ID | null