From 852d27b5b3b1cdbd6ca724cebb2be8d82a15d0c7 Mon Sep 17 00:00:00 2001 From: Eddie Li Date: Fri, 13 Aug 2021 17:31:08 -0400 Subject: [PATCH 1/2] allow custom host id when creating new entity for orderable assets --- .../src/service/services/asset.service.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/core/src/service/services/asset.service.ts b/packages/core/src/service/services/asset.service.ts index 9e8e89b641..7912e2388f 100644 --- a/packages/core/src/service/services/asset.service.ts +++ b/packages/core/src/service/services/asset.service.ts @@ -45,6 +45,9 @@ import { TransactionalConnection } from '../transaction/transactional-connection import { ChannelService } from './channel.service'; import { RoleService } from './role.service'; import { TagService } from './tag.service'; + +import { camelCase } from 'typeorm/util/StringUtils'; + // tslint:disable-next-line:no-var-requires const sizeOf = require('image-size'); @@ -557,15 +560,19 @@ export class AssetService { private getHostEntityIdProperty(entity: EntityWithAssets): string { const entityName = entity.constructor.name; - switch (entityName) { - case 'Product': - return 'productId'; - case 'ProductVariant': - return 'productVariantId'; - case 'Collection': - return 'collectionId'; - default: - throw new InternalServerError('error.could-not-find-matching-orderable-asset'); + try { + switch (entityName) { + case 'Product': + return 'productId'; + case 'ProductVariant': + return 'productVariantId'; + case 'Collection': + return 'collectionId'; + default: + return `${camelCase(entityName, true)}Id`; + } + } catch (error) { + throw new InternalServerError('error.could-not-find-matching-orderable-asset'); } } From 16ba89b0ec44509caa725e137d507ed213c95d70 Mon Sep 17 00:00:00 2001 From: Eddie Li Date: Wed, 18 Aug 2021 07:46:16 -0400 Subject: [PATCH 2/2] fixed comment --- .../src/service/services/asset.service.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/core/src/service/services/asset.service.ts b/packages/core/src/service/services/asset.service.ts index 7912e2388f..6cbe51ceb1 100644 --- a/packages/core/src/service/services/asset.service.ts +++ b/packages/core/src/service/services/asset.service.ts @@ -560,20 +560,16 @@ export class AssetService { private getHostEntityIdProperty(entity: EntityWithAssets): string { const entityName = entity.constructor.name; - try { - switch (entityName) { - case 'Product': - return 'productId'; - case 'ProductVariant': - return 'productVariantId'; - case 'Collection': - return 'collectionId'; - default: - return `${camelCase(entityName, true)}Id`; - } - } catch (error) { - throw new InternalServerError('error.could-not-find-matching-orderable-asset'); - } + switch (entityName) { + case 'Product': + return 'productId'; + case 'ProductVariant': + return 'productVariantId'; + case 'Collection': + return 'collectionId'; + default: + return `${camelCase(entityName, true)}Id`; + } } private validateMimeType(mimeType: string): boolean {