diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-26 00:22:26 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-26 00:22:26 +0200 |
commit | 6f16392aa452c07e60ac4775b002c26f02e27609 (patch) | |
tree | dba49954cfdf4b673afd17925a5a84d287481bac /util/src | |
parent | :bug: patch modules (diff) | |
download | server-6f16392aa452c07e60ac4775b002c26f02e27609.tar.xz |
:sparkles: unit test
Diffstat (limited to 'util/src')
-rw-r--r-- | util/src/entities/BaseClass.ts | 14 | ||||
-rw-r--r-- | util/src/entities/User.ts | 2 | ||||
-rw-r--r-- | util/src/index.ts | 3 | ||||
-rw-r--r-- | util/src/util/Database.ts | 5 | ||||
-rw-r--r-- | util/src/util/checkToken.ts | 2 | ||||
-rw-r--r-- | util/src/util/index.ts | 3 |
6 files changed, 16 insertions, 13 deletions
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts index 38f6a71b..22d9f6d6 100644 --- a/util/src/entities/BaseClass.ts +++ b/util/src/entities/BaseClass.ts @@ -8,6 +8,7 @@ const ajv = new Ajv({ removeAdditional: "all", useDefaults: true, coerceTypes: true, + // @ts-ignore validateFormats: false, allowUnionTypes: true, }); @@ -23,12 +24,18 @@ export class BaseClass extends BaseEntity { this.assign(props); if (!this.construct.schema) this.construct.schema = { ...schema, $ref: `#/definitions/${this.construct.name}` }; + + this.id = this.opts.id || Snowflake.generate(); } get construct(): any { return this.constructor; } + get metadata() { + return this.construct.getRepository().metadata; + } + assign(props: any) { if (!props || typeof props !== "object") return; @@ -39,8 +46,6 @@ export class BaseClass extends BaseEntity { Object.defineProperty(this, key, { value: props[key] }); } - - this.id = this.opts.id || Snowflake.generate(); } @BeforeUpdate() @@ -48,10 +53,7 @@ export class BaseClass extends BaseEntity { validate() { const valid = ajv.validate(this.construct.schema, this.toJSON()); if (!valid) throw ajv.errors; - } - - get metadata() { - return this.construct.getRepository().metadata; + return this; } toJSON(): any { diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 073f6217..39e59da4 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -1,4 +1,4 @@ -import { Column, Entity, JoinColumn, OneToMany, OneToOne } from "typeorm"; +import { Column, Entity, JoinColumn, OneToMany } from "typeorm"; import { BaseClass } from "./BaseClass"; import { BitField } from "../util/BitField"; import { Relationship } from "./Relationship"; diff --git a/util/src/index.ts b/util/src/index.ts index d66af15b..f3bd9e9b 100644 --- a/util/src/index.ts +++ b/util/src/index.ts @@ -1,10 +1,9 @@ import "reflect-metadata"; // export * as Constants from "../util/Constants"; +export * from "./util/index"; export * from "./interfaces/index"; export * from "./entities/index"; -export * from "./util/index"; -import "./test"; // import Config from "../util/Config"; // import db, { MongooseCache, toObject } from "./util/Database"; diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index 248e0dcf..90ba9079 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -10,6 +10,7 @@ var promise: Promise<any>; export function initDatabase() { if (promise) return promise; // prevent initalizing multiple times + console.log("[Database] connecting ..."); // @ts-ignore promise = createConnection({ type: "sqlite", @@ -19,7 +20,7 @@ export function initDatabase() { logging: false, }); + promise.then(() => console.log("[Database] connected")); + return promise; } - -initDatabase(); diff --git a/util/src/util/checkToken.ts b/util/src/util/checkToken.ts index 825ee00c..58e537ea 100644 --- a/util/src/util/checkToken.ts +++ b/util/src/util/checkToken.ts @@ -9,7 +9,7 @@ export function checkToken(token: string, jwtSecret: string): Promise<any> { jwt.verify(token, jwtSecret, JWTOptions, async (err, decoded: any) => { if (err || !decoded) return rej("Invalid Token"); - const user = await User.findOneOrFail( + const user = await User.findOne( { id: decoded.id }, { select: ["user_data", "bot", "disabled", "deleted"] } ); diff --git a/util/src/util/index.ts b/util/src/util/index.ts index 886a2390..700ecfa5 100644 --- a/util/src/util/index.ts +++ b/util/src/util/index.ts @@ -1,7 +1,8 @@ +export * from "./Database"; + export * from "./Regex"; export * from "./String"; export * from "./BitField"; -export * from "./Database"; export * from "./Intents"; export * from "./MessageFlags"; export * from "./Permissions"; |