vylbot-app/src/entity/Role.ts
Vylpes ed8f5927c8
Feature/81 slash command support (#192)
* Update discord.js

* Migrate to slash commands

* Clean up imports

* Update permissions

* Fix guild-specific commands not showing up

* Fix changes requested
2022-09-18 11:57:22 +01:00

48 lines
1.2 KiB
TypeScript

import { Column, Entity, 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 SetServer(server: Server) {
this.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;
}
}