150 assignable roles should be its own table to prevent limitations on length (#158)
* Add entity * Update role config command to use new entity * Update role command to use new entity * Remove legacy code from config command
This commit is contained in:
parent
6522bee37b
commit
514be692fd
6 changed files with 126 additions and 37 deletions
44
src/entity/Role.ts
Normal file
44
src/entity/Role.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { Column, Entity, EntityTarget, getConnection, ManyToOne } from "typeorm";
|
||||
import BaseEntity from "../contracts/BaseEntity"
|
||||
import Server from "./Server";
|
||||
|
||||
@Entity()
|
||||
export default class Role extends BaseEntity {
|
||||
constructor(roleId: string) {
|
||||
super();
|
||||
|
||||
this.RoleId = roleId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
RoleId: string;
|
||||
|
||||
@ManyToOne(() => Server, x => x.Roles)
|
||||
Server: Server;
|
||||
|
||||
public static async FetchOneByRoleId(roleId: string, relations?: string[]): Promise<Role | undefined> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository(Role);
|
||||
|
||||
const single = await repository.findOne({ RoleId: roleId}, { relations: relations || [] });
|
||||
|
||||
return single;
|
||||
}
|
||||
|
||||
public static async FetchAllByServerId(serverId: string): Promise<Role[]> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository(Server);
|
||||
|
||||
const all = await repository.findOne(serverId, { relations: [
|
||||
"Roles",
|
||||
]});
|
||||
|
||||
if (!all) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return all.Roles;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { Column, Entity, getConnection, OneToMany } from "typeorm";
|
||||
import { Entity, OneToMany } from "typeorm";
|
||||
import BaseEntity from "../contracts/BaseEntity";
|
||||
import Role from "./Role";
|
||||
import Setting from "./Setting";
|
||||
|
||||
@Entity()
|
||||
|
@ -13,7 +14,14 @@ export default class Server extends BaseEntity {
|
|||
@OneToMany(() => Setting, x => x.Server)
|
||||
Settings: Setting[];
|
||||
|
||||
@OneToMany(() => Role, x => x.Server)
|
||||
Roles: Role[];
|
||||
|
||||
public AddSettingToServer(setting: Setting) {
|
||||
this.Settings.push(setting);
|
||||
}
|
||||
|
||||
public AddRoleToServer(role: Role) {
|
||||
this.Roles.push(role);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue