Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom host id when creating new entity for orderable assets #1035

Merged
merged 2 commits into from Aug 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/core/src/service/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try-catch block is redundant, since there is no possibility of an error being thrown from the switch statement. You can omit this and just use the switch statement instead.

throw new InternalServerError('error.could-not-find-matching-orderable-asset');
}
}

Expand Down