Reorganize project. Add folder for shared code between backend/dashboard. Switch from jest to ava for tests.
This commit is contained in:
parent
80a82fe348
commit
16111bbe84
162 changed files with 11056 additions and 9900 deletions
62
backend/src/data/GuildReactionRoles.ts
Normal file
62
backend/src/data/GuildReactionRoles.ts
Normal file
|
@ -0,0 +1,62 @@
|
|||
import { ReactionRole } from "./entities/ReactionRole";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
|
||||
export class GuildReactionRoles extends BaseGuildRepository {
|
||||
private reactionRoles: Repository<ReactionRole>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.reactionRoles = getRepository(ReactionRole);
|
||||
}
|
||||
|
||||
async all(): Promise<ReactionRole[]> {
|
||||
return this.reactionRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getForMessage(messageId: string): Promise<ReactionRole[]> {
|
||||
return this.reactionRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole> {
|
||||
return this.reactionRoles.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId,
|
||||
emoji,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async removeFromMessage(messageId: string, emoji: string = null) {
|
||||
const criteria: any = {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId,
|
||||
};
|
||||
|
||||
if (emoji) {
|
||||
criteria.emoji = emoji;
|
||||
}
|
||||
|
||||
await this.reactionRoles.delete(criteria);
|
||||
}
|
||||
|
||||
async add(channelId: string, messageId: string, emoji: string, roleId: string) {
|
||||
await this.reactionRoles.insert({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
message_id: messageId,
|
||||
emoji,
|
||||
role_id: roleId,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue