1 files changed, 13 insertions, 9 deletions
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts
index 403a6fc6..9b2ce058 100644
--- a/util/src/entities/BaseClass.ts
+++ b/util/src/entities/BaseClass.ts
@@ -6,11 +6,7 @@ import "missing-native-js-functions";
// TODO use class-validator https://typeorm.io/#/validation with class annotators (isPhone/isEmail) combined with types from typescript-json-schema
// btw. we don't use class-validator for everything, because we need to explicitly set the type instead of deriving it from typescript also it doesn't easily support nested objects
-export class BaseClass extends BaseEntity {
- @PrimaryColumn()
- id: string;
-
- // @ts-ignore
+export class BaseClassWithoutId extends BaseEntity {
constructor(private props?: any) {
super();
this.assign(props);
@@ -24,8 +20,7 @@ export class BaseClass extends BaseEntity {
return this.construct.getRepository().metadata as EntityMetadata;
}
- assign(props: any) {
- if (!props || typeof props !== "object") return;
+ assign(props: any = {}) {
delete props.opts;
delete props.props;
@@ -48,8 +43,6 @@ export class BaseClass extends BaseEntity {
this[key] = props[key];
}
}
-
- if (!this.id) this.id = Snowflake.generate();
}
@BeforeUpdate()
@@ -77,3 +70,14 @@ export class BaseClass extends BaseEntity {
return repository.decrement(conditions, propertyPath, value);
}
}
+
+export class BaseClass extends BaseClassWithoutId {
+ @PrimaryColumn()
+ id: string;
+
+ assign(props: any = {}) {
+ super.assign(props);
+ if (!this.id) this.id = Snowflake.generate();
+ return this;
+ }
+}
|