summary refs log tree commit diff
path: root/util/src/entities/BaseClass.ts
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-08 04:27:28 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-09 23:28:27 +0200
commitd52d9c62fc30e31e2c01bf6b63f9aedebdde216f (patch)
treee0f7fd130aeeecb9964e1f359eea6b4e124de7da /util/src/entities/BaseClass.ts
parentClean dependencies (diff)
downloadserver-d52d9c62fc30e31e2c01bf6b63f9aedebdde216f.tar.xz
Bunch of fixes and improvements, everything appears to work now
Diffstat (limited to 'util/src/entities/BaseClass.ts')
-rw-r--r--util/src/entities/BaseClass.ts21
1 files changed, 15 insertions, 6 deletions
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<this> {
+		if (!this.id) this.id = Snowflake.generate();
+		return super.save(options);
+	}
 }