|
|
@@ -2,19 +2,14 @@
|
|
|
import { CustomFieldType } from '@vendure/common/lib/shared-types';
|
|
|
import { assertNever } from '@vendure/common/lib/shared-utils';
|
|
|
import {
|
|
|
- AfterLoad,
|
|
|
- BeforeUpdate,
|
|
|
Column,
|
|
|
ColumnOptions,
|
|
|
ColumnType,
|
|
|
DataSourceOptions,
|
|
|
- EntitySubscriberInterface,
|
|
|
- EventSubscriber,
|
|
|
getMetadataArgsStorage,
|
|
|
Index,
|
|
|
JoinColumn,
|
|
|
JoinTable,
|
|
|
- LoadEvent,
|
|
|
ManyToMany,
|
|
|
ManyToOne,
|
|
|
} from 'typeorm';
|
|
|
@@ -24,7 +19,6 @@ import { DateUtils } from 'typeorm/util/DateUtils';
|
|
|
import { CustomFieldConfig, CustomFields } from '../config/custom-field/custom-field-types';
|
|
|
import { Logger } from '../config/logger/vendure-logger';
|
|
|
import { VendureConfig } from '../config/vendure-config';
|
|
|
-import { VendureEntity } from './base/base.entity';
|
|
|
|
|
|
/**
|
|
|
* The maximum length of the "length" argument of a MySQL varchar column.
|
|
|
@@ -39,8 +33,7 @@ function registerCustomFieldsForEntity(
|
|
|
entityName: keyof CustomFields,
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-function-type
|
|
|
ctor: { new (): any },
|
|
|
- translation: boolean,
|
|
|
- targetEntity: Function,
|
|
|
+ translation = false,
|
|
|
) {
|
|
|
const customFields = config.customFields && config.customFields[entityName];
|
|
|
const dbEngine = config.dbConnectionOptions.type;
|
|
|
@@ -109,25 +102,6 @@ function registerCustomFieldsForEntity(
|
|
|
// sufficient to add the `unique: true` property to the column options.
|
|
|
Index({ unique: true })(instance, name);
|
|
|
}
|
|
|
- if (customField.type === 'string' && customField.encryptionSecret) {
|
|
|
- @EventSubscriber()
|
|
|
- class DynamicSubscriber implements EntitySubscriberInterface {
|
|
|
- listenTo() {
|
|
|
- return targetEntity;
|
|
|
- }
|
|
|
-
|
|
|
- afterLoad(entity: any, event?: LoadEvent<any>): Promise<any> | void {}
|
|
|
-
|
|
|
- beforeInsert(event: any) {
|
|
|
- console.log(`beforeInsert: ${event}`);
|
|
|
- }
|
|
|
- beforeUpdate(event: any) {
|
|
|
- console.log(`beforeUpdate: ${event}`);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- (config.dbConnectionOptions.subscribers as any[]).push(DynamicSubscriber);
|
|
|
- }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -271,13 +245,7 @@ export function registerCustomEntityFields(config: VendureConfig) {
|
|
|
const customFieldsMetadata = getCustomFieldsMetadata(entityName);
|
|
|
const customFieldsClass = customFieldsMetadata.type();
|
|
|
if (customFieldsClass && typeof customFieldsClass !== 'string') {
|
|
|
- registerCustomFieldsForEntity(
|
|
|
- config,
|
|
|
- entityName,
|
|
|
- customFieldsClass as any,
|
|
|
- false,
|
|
|
- customFieldsMetadata.target as Function,
|
|
|
- );
|
|
|
+ registerCustomFieldsForEntity(config, entityName, customFieldsClass as any);
|
|
|
}
|
|
|
const translationsMetadata = metadataArgsStorage
|
|
|
.filterRelations(customFieldsMetadata.target)
|
|
|
@@ -295,7 +263,6 @@ export function registerCustomEntityFields(config: VendureConfig) {
|
|
|
entityName,
|
|
|
customFieldsTranslationClass as any,
|
|
|
true,
|
|
|
- customFieldsMetadata.target as Function,
|
|
|
);
|
|
|
}
|
|
|
} else {
|