Kaynağa Gözat

fix(core): Fix missing customField input for Assets

Co-authored-by: Kevin Mattutat <kevin.mattutat@spaceparrots.de>

Fixes #844
Drayke 4 yıl önce
ebeveyn
işleme
772bd8db98

+ 6 - 1
packages/core/src/service/services/asset.service.ts

@@ -40,6 +40,7 @@ import { AssetEvent } from '../../event-bus/events/asset-event';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
 import { patchEntity } from '../helpers/utils/patch-entity';
 import { patchEntity } from '../helpers/utils/patch-entity';
 import { TransactionalConnection } from '../transaction/transactional-connection';
 import { TransactionalConnection } from '../transaction/transactional-connection';
+import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
 
 
 import { ChannelService } from './channel.service';
 import { ChannelService } from './channel.service';
 import { RoleService } from './role.service';
 import { RoleService } from './role.service';
@@ -69,6 +70,7 @@ export class AssetService {
         private tagService: TagService,
         private tagService: TagService,
         private channelService: ChannelService,
         private channelService: ChannelService,
         private roleService: RoleService,
         private roleService: RoleService,
+        private customFieldRelationService: CustomFieldRelationService,
     ) {
     ) {
         this.permittedMimeTypes = this.configService.assetOptions.permittedFileTypes
         this.permittedMimeTypes = this.configService.assetOptions.permittedFileTypes
             .map(val => (/\.[\w]+/.test(val) ? mime.lookup(val) || undefined : val))
             .map(val => (/\.[\w]+/.test(val) ? mime.lookup(val) || undefined : val))
@@ -235,10 +237,11 @@ export class AssetService {
     async create(ctx: RequestContext, input: CreateAssetInput): Promise<CreateAssetResult> {
     async create(ctx: RequestContext, input: CreateAssetInput): Promise<CreateAssetResult> {
         const { createReadStream, filename, mimetype } = await input.file;
         const { createReadStream, filename, mimetype } = await input.file;
         const stream = createReadStream();
         const stream = createReadStream();
-        const result = await this.createAssetInternal(ctx, stream, filename, mimetype);
+        const result = await this.createAssetInternal(ctx, stream, filename, mimetype, input.customFields);
         if (isGraphQlErrorResult(result)) {
         if (isGraphQlErrorResult(result)) {
             return result;
             return result;
         }
         }
+        await this.customFieldRelationService.updateRelations(ctx, Asset, input, result);
         if (input.tags) {
         if (input.tags) {
             const tags = await this.tagService.valuesToTags(ctx, input.tags);
             const tags = await this.tagService.valuesToTags(ctx, input.tags);
             result.tags = tags;
             result.tags = tags;
@@ -419,6 +422,7 @@ export class AssetService {
         stream: Stream,
         stream: Stream,
         filename: string,
         filename: string,
         mimetype: string,
         mimetype: string,
+        customFields?: { [key: string]: any }
     ): Promise<Asset | MimeTypeError> {
     ): Promise<Asset | MimeTypeError> {
         const { assetOptions } = this.configService;
         const { assetOptions } = this.configService;
         if (!this.validateMimeType(mimetype)) {
         if (!this.validateMimeType(mimetype)) {
@@ -454,6 +458,7 @@ export class AssetService {
             source: sourceFileIdentifier,
             source: sourceFileIdentifier,
             preview: previewFileIdentifier,
             preview: previewFileIdentifier,
             focalPoint: null,
             focalPoint: null,
+            customFields
         });
         });
         this.channelService.assignToCurrentChannel(asset, ctx);
         this.channelService.assignToCurrentChannel(asset, ctx);
         return this.connection.getRepository(ctx, Asset).save(asset);
         return this.connection.getRepository(ctx, Asset).save(asset);