Skip to content

Commit 4973303

Browse files
committed
refactor: added constant for separator
1 parent 54d9a49 commit 4973303

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const POLYMORPHIC_OPTIONS = 'POLYMORPHIC_OPTIONS';
2+
export const POLYMORPHIC_KEY_SEPARATOR = '::';

src/decorators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { POLYMORPHIC_OPTIONS } from './constants';
1+
import { POLYMORPHIC_KEY_SEPARATOR, POLYMORPHIC_OPTIONS } from './constants';
22
import {
33
PolymorphicDecoratorOptionsInterface,
44
PolymorphicMetadataOptionsInterface,
@@ -9,7 +9,7 @@ const polymorphicPropertyDecorator = (
99
): PropertyDecorator => (target: Object, propertyKey: string) => {
1010
Reflect.defineMetadata(POLYMORPHIC_OPTIONS, true, target);
1111
Reflect.defineMetadata(
12-
`${POLYMORPHIC_OPTIONS}::${propertyKey}`,
12+
`${POLYMORPHIC_OPTIONS}${POLYMORPHIC_KEY_SEPARATOR}${propertyKey}`,
1313
{
1414
propertyKey,
1515
...options,

src/polymorphic.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
FindOneOptions,
1010
ObjectID,
1111
} from 'typeorm';
12-
import { POLYMORPHIC_OPTIONS } from './constants';
12+
import { POLYMORPHIC_KEY_SEPARATOR, POLYMORPHIC_OPTIONS } from './constants';
1313
import {
1414
PolymorphicChildType,
1515
PolymorphicParentType,
@@ -46,7 +46,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
4646

4747
return keys.reduce<Array<PolymorphicMetadataInterface>>(
4848
(keys: PolymorphicMetadataInterface[], key: string) => {
49-
if (key.split('::')[0] === POLYMORPHIC_OPTIONS) {
49+
if (key.split(POLYMORPHIC_KEY_SEPARATOR)[0] === POLYMORPHIC_OPTIONS) {
5050
const data: PolymorphicMetadataOptionsInterface & {
5151
propertyKey: string;
5252
} = Reflect.getMetadata(

0 commit comments

Comments
 (0)