AssetService
AssetService
Contains methods relating to Asset entities.
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
(connection: TransactionalConnection, configService: ConfigService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus, tagService: TagService, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService) => AssetService
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>
Returns the Assets of an entity which has a well-ordered list of Assets, such as Product, ProductVariant or Collection.
updateFeaturedAsset
(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>
updateEntityAssets
(ctx: RequestContext, entity: T, input: EntityAssetInput) => Promise<T>
Updates the assets / featuredAsset of an entity, ensuring that only valid assetIds are used.
create
(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
(ctx: RequestContext, input: UpdateAssetInput) => Promise<Asset>
Updates the name, focalPoint, tags & custom fields of an Asset.
delete
(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
(ctx: RequestContext, input: AssignAssetsToChannelInput) => Promise<Asset[]>
createFromFileStream
(stream: ReadStream, ctx?: RequestContext) => Promise<CreateAssetResult>
Create an Asset from a file stream, for example to create an Asset during data import.
createFromFileStream
(stream: Readable, filePath: string, ctx?: RequestContext) => Promise<CreateAssetResult>
createFromFileStream
(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.
interface EntityWithAssets extends VendureEntity {
featuredAsset: Asset | null;
assets: OrderableAsset[];
}
- Extends:
VendureEntity
EntityAssetInput
Used when updating entities which implement EntityWithAssets.
interface EntityAssetInput {
assetIds?: ID[] | null;
featuredAssetId?: ID | null;
}