vylbot-app/src/entity/Role.ts
Vylpes aa070bb7a7
v3.0.2 (#159)
* Change lobby command to error upon making a duplicate lobby channel (#154)

* Update lobby command to give proper errors if role or channel id cannot be found (#156)

* Add bunny command back (#157)

* 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

* Update .env template to current date
2022-05-16 18:41:15 +01:00

44 lines
1.1 KiB
TypeScript

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;
}
}