mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
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
57
backend/src/data/GuildAutoReactions.ts
Normal file
57
backend/src/data/GuildAutoReactions.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { AutoReaction } from "./entities/AutoReaction";
|
||||
|
||||
export class GuildAutoReactions extends BaseGuildRepository {
|
||||
private autoReactions: Repository<AutoReaction>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.autoReactions = getRepository(AutoReaction);
|
||||
}
|
||||
|
||||
async all(): Promise<AutoReaction[]> {
|
||||
return this.autoReactions.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getForChannel(channelId: string): Promise<AutoReaction> {
|
||||
return this.autoReactions.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async removeFromChannel(channelId: string) {
|
||||
await this.autoReactions.delete({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
});
|
||||
}
|
||||
|
||||
async set(channelId: string, reactions: string[]) {
|
||||
const existingRecord = await this.getForChannel(channelId);
|
||||
if (existingRecord) {
|
||||
this.autoReactions.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
},
|
||||
{
|
||||
reactions,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await this.autoReactions.insert({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
reactions,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue