3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 23:09:59 +00:00
zeppelin/backend/src/data/GuildPingableRoles.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-07-01 12:17:45 +00:00
import { Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
2023-07-01 12:17:45 +00:00
import { dataSource } from "./dataSource";
2019-01-12 14:09:11 +02:00
import { PingableRole } from "./entities/PingableRole";
export class GuildPingableRoles extends BaseGuildRepository {
2019-01-12 14:09:11 +02:00
private pingableRoles: Repository<PingableRole>;
constructor(guildId) {
super(guildId);
2023-07-01 12:17:45 +00:00
this.pingableRoles = dataSource.getRepository(PingableRole);
2019-01-12 14:09:11 +02:00
}
async all(): Promise<PingableRole[]> {
return this.pingableRoles.find({
where: {
guild_id: this.guildId,
},
2019-01-12 14:09:11 +02:00
});
}
async getForChannel(channelId: string): Promise<PingableRole[]> {
return this.pingableRoles.find({
where: {
guild_id: this.guildId,
channel_id: channelId,
},
2019-01-12 14:09:11 +02:00
});
}
2023-07-01 12:17:45 +00:00
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole | null> {
2019-01-12 14:09:11 +02:00
return this.pingableRoles.findOne({
where: {
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
},
2019-01-12 14:09:11 +02:00
});
}
async delete(channelId: string, roleId: string) {
await this.pingableRoles.delete({
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
2019-01-12 14:09:11 +02:00
});
}
async add(channelId: string, roleId: string) {
await this.pingableRoles.insert({
guild_id: this.guildId,
channel_id: channelId,
role_id: roleId,
2019-01-12 14:09:11 +02:00
});
}
}