From 698ad90d3e82a15b85ceb021ad5667109ac0bcdb Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Fri, 31 Mar 2023 15:26:15 +1100 Subject: Revert "Merge pull request #1008 from spacebarchat/dev/samuel" This reverts commit 69ea71aa9e0bd2e5a98904a66fba0ad3745707cb, reversing changes made to 8b2faf0b18336e5dff1eeff4e849bcfd96b09e88. --- src/util/entities/BaseClass.ts | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/util/entities/BaseClass.ts') diff --git a/src/util/entities/BaseClass.ts b/src/util/entities/BaseClass.ts index d2770bfd..f4b3cf59 100644 --- a/src/util/entities/BaseClass.ts +++ b/src/util/entities/BaseClass.ts @@ -25,12 +25,16 @@ import { PrimaryColumn, } from "typeorm"; import { Snowflake } from "../util/Snowflake"; +import { getDatabase } from "../util/Database"; import { OrmUtils } from "../imports/OrmUtils"; -import { getDatabase } from "../util"; export class BaseClassWithoutId extends BaseEntity { - public get metadata() { - return getDatabase()?.getMetadata(this.constructor); + private get construct() { + return this.constructor; + } + + private get metadata() { + return getDatabase()?.getMetadata(this.construct); } assign(props: object) { @@ -57,23 +61,8 @@ export class BaseClassWithoutId extends BaseEntity { ), ); } -} - -export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") - ? ObjectIdColumn - : PrimaryColumn; - -export class BaseClassWithId extends BaseClassWithoutId { - @PrimaryIdColumn() - id: string = Snowflake.generate(); - - @BeforeUpdate() - @BeforeInsert() - _do_validate() { - if (!this.id) this.id = Snowflake.generate(); - } - static increment( + static increment( conditions: FindOptionsWhere, propertyPath: string, value: number | string, @@ -82,7 +71,7 @@ export class BaseClassWithId extends BaseClassWithoutId { return repository.increment(conditions, propertyPath, value); } - static decrement( + static decrement( conditions: FindOptionsWhere, propertyPath: string, value: number | string, @@ -91,3 +80,18 @@ export class BaseClassWithId extends BaseClassWithoutId { return repository.decrement(conditions, propertyPath, value); } } + +export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") + ? ObjectIdColumn + : PrimaryColumn; + +export class BaseClass extends BaseClassWithoutId { + @PrimaryIdColumn() + id: string = Snowflake.generate(); + + @BeforeUpdate() + @BeforeInsert() + _do_validate() { + if (!this.id) this.id = Snowflake.generate(); + } +} -- cgit 1.5.1