summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2022-08-10 00:31:01 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2022-08-10 00:31:01 +0200
commit9a5ccd6a9de2a23dbedb832f4e731db06f0381c5 (patch)
tree609d44ff27e2147fbefade56b98ea33bf56d1331
parentwip(util): benchmark (diff)
downloadserver-9a5ccd6a9de2a23dbedb832f4e731db06f0381c5.tar.xz
fix(util): OrmUtils
-rw-r--r--util/scripts/benchmark.js12
-rw-r--r--util/src/entities/Channel.ts2
-rw-r--r--util/src/entities/Guild.ts2
-rw-r--r--util/src/entities/Member.ts2
-rw-r--r--util/src/entities/User.ts6
5 files changed, 15 insertions, 9 deletions
diff --git a/util/scripts/benchmark.js b/util/scripts/benchmark.js
index f4f34e9e..e7435191 100644
--- a/util/scripts/benchmark.js
+++ b/util/scripts/benchmark.js
@@ -1,22 +1,28 @@
 const typeorm = require("typeorm");
-const Database = require("../dist/util/Database");
 const Models = require("../dist/entities");
+const { PrimaryColumn } = require("typeorm");
 
 function shouldIncludeEntity(name) {
-	return ![BaseClassWithoutId, PrimaryColumn, BaseClass, PrimaryGeneratedColumn].map((x) => x.name).includes(name);
+	return ![Models.BaseClassWithoutId, PrimaryColumn, Models.BaseClass, Models.PrimaryGeneratedColumn]
+		.map((x) => x?.name)
+		.includes(name);
 }
 
 async function main() {
+	console.log("starting");
 	const db = new typeorm.DataSource({
-		driver: "sqlite",
+		type: "sqlite",
 		database: ":memory:",
 		entities: Object.values(Models).filter((x) => x.constructor.name == "Function" && shouldIncludeEntity(x.name)),
+		synchronize: true,
 	});
 	await db.initialize();
+	console.log("Initialized database");
 
 	for (var i = 0; i < 100; i++) {
 		await Models.User.register({ username: "User" + i });
 		console.log("registered user " + i);
 	}
 }
+
 main();
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index 35f1956c..92940b34 100644
--- a/util/src/entities/Channel.ts
+++ b/util/src/entities/Channel.ts
@@ -1,5 +1,5 @@
 import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";

-import { OrmUtils } from "typeorm/util/OrmUtils";

+import { OrmUtils } from "../util/imports/OrmUtils";

 import { BaseClass } from "./BaseClass";

 import { Guild } from "./Guild";

 import { PublicUserProjection, User } from "./User";

diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts
index c314ecb9..77a04350 100644
--- a/util/src/entities/Guild.ts
+++ b/util/src/entities/Guild.ts
@@ -1,5 +1,5 @@
 import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToMany, OneToOne, RelationId } from "typeorm";
-import { OrmUtils } from "typeorm/util/OrmUtils";
+import { OrmUtils } from "../util/imports/OrmUtils";
 import { Config, handleFile, Snowflake } from "..";
 import { Ban } from "./Ban";
 import { BaseClass } from "./BaseClass";
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts
index c356c26d..d4395e03 100644
--- a/util/src/entities/Member.ts
+++ b/util/src/entities/Member.ts
@@ -25,7 +25,7 @@ import { Role } from "./Role";
 import { BaseClassWithoutId } from "./BaseClass";
 import { Ban, PublicGuildRelations } from ".";
 import { DiscordApiErrors } from "../util/Constants";
-import { OrmUtils } from "typeorm/util/OrmUtils";
+import { OrmUtils } from "../util/imports/OrmUtils";
 
 export const MemberPrivateProjection: (keyof Member)[] = [
 	"id",
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 7cd6c3d8..7e3c7457 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -1,5 +1,5 @@
 import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, OneToMany } from "typeorm";
-import { OrmUtils } from "typeorm/util/OrmUtils";
+import { OrmUtils } from "../util/imports/OrmUtils";
 import { BaseClass } from "./BaseClass";
 import { BitField } from "../util/BitField";
 import { Relationship } from "./Relationship";
@@ -245,7 +245,7 @@ export class User extends BaseClass {
 			throw FieldErrors({
 				username: {
 					code: "USERNAME_TOO_MANY_USERS",
-					message: req.t("auth:register.USERNAME_TOO_MANY_USERS"),
+					message: req?.t("auth:register.USERNAME_TOO_MANY_USERS"),
 				},
 			});
 		}
@@ -253,7 +253,7 @@ export class User extends BaseClass {
 		// TODO: save date_of_birth
 		// appearently discord doesn't save the date of birth and just calculate if nsfw is allowed
 		// if nsfw_allowed is null/undefined it'll require date_of_birth to set it to true/false
-		const language = req.language === "en" ? "en-US" : req.language || "en-US";
+		const language = req?.language === "en" ? "en-US" : req?.language || "en-US";
 
 		const user = OrmUtils.mergeDeep(new User(), {
 			created_at: new Date(),