3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 15:00:00 +00:00
zeppelin/src/data/GuildPingableRoles.ts
Dragory d54897acdd Split BaseRepository into non-guild and guild
BaseRepository includes all the non-guild-specific functionality,
such as with() and getRelations().
BaseGuildRepository includes guild-specific functionality, such as
getInstance().
2019-05-25 21:25:34 +03:00

55 lines
1.3 KiB
TypeScript

import { BaseGuildRepository } from "./BaseGuildRepository";
import { getRepository, Repository } from "typeorm";
import { PingableRole } from "./entities/PingableRole";
export class GuildPingableRoles extends BaseGuildRepository {
private pingableRoles: Repository<PingableRole>;
constructor(guildId) {
super(guildId);
this.pingableRoles = getRepository(PingableRole);
}
async all(): Promise<PingableRole[]> {
return this.pingableRoles.find({
where: {
guild_id: this.guildId,
},
});
}
async getForChannel(channelId: string): Promise<PingableRole[]> {
return this.pingableRoles.find({
where: {
guild_id: this.guildId,
channel_id: channelId,
},
});
}
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole> {
return this.pingableRoles.findOne({
where: {
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
},
});
}
async delete(channelId: string, roleId: string) {
await this.pingableRoles.delete({
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
});
}
async add(channelId: string, roleId: string) {
await this.pingableRoles.insert({
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
});
}
}