From d52d9c62fc30e31e2c01bf6b63f9aedebdde216f Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 8 Aug 2022 04:27:28 +0200 Subject: Bunch of fixes and improvements, everything appears to work now --- util/src/entities/BaseClass.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'util/src/entities/BaseClass.ts') diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts index 0cb885fa..1ab75a5a 100644 --- a/util/src/entities/BaseClass.ts +++ b/util/src/entities/BaseClass.ts @@ -1,11 +1,12 @@ import "reflect-metadata"; -import { BaseEntity, EntityMetadata, ObjectIdColumn, PrimaryColumn, FindOptionsWhere } from "typeorm"; +import { BaseEntity, EntityMetadata, ObjectIdColumn, PrimaryColumn, FindOptionsWhere, Generated, SaveOptions } from "typeorm"; import { Snowflake } from "../util/Snowflake"; export class BaseClassWithoutId extends BaseEntity { constructor(props?: any) { super(); - this.assign(props); + if(props != undefined && props != null && Object.keys(props).length > 0) + this.assign(props); } assign(props: any = {}) { @@ -13,8 +14,11 @@ export class BaseClassWithoutId extends BaseEntity { delete props.opts; delete props.props; // will not include relational properties - - for (const key in props) { + console.warn("WARNING: BaseClass.assign called! This will probably fail!"); + console.warn(this) + Object.assign(this,props); + if(/--debug|--inspect/.test(process.execArgv.join(' '))) debugger; + /*for (const key in props) { // @ts-ignore const setter = this[`set${key.capitalize()}`]; // use setter function if it exists @@ -24,7 +28,7 @@ export class BaseClassWithoutId extends BaseEntity { // @ts-ignore this[key] = props[key]; } - } + }*/ } } @@ -35,8 +39,13 @@ export class BaseClass extends BaseClassWithoutId { id: string; assign(props: any = {}) { - super.assign(props); + super.assign(props); if (!this.id) this.id = Snowflake.generate(); return this; } + + save(options?: SaveOptions | undefined): Promise { + if (!this.id) this.id = Snowflake.generate(); + return super.save(options); + } } -- cgit 1.5.1