mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-04 10:55:44 +00:00
fix(util): OrmUtils
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user