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

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-02-20 00:01:14 +02:00
import { getRepository, Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
2019-02-20 00:01:14 +02:00
import { Reminder } from "./entities/Reminder";
export class GuildReminders extends BaseGuildRepository {
2019-02-20 00:01:14 +02:00
private reminders: Repository<Reminder>;
constructor(guildId) {
super(guildId);
this.reminders = getRepository(Reminder);
}
async getDueReminders(): Promise<Reminder[]> {
return this.reminders
.createQueryBuilder()
.where("guild_id = :guildId", { guildId: this.guildId })
.andWhere("remind_at <= NOW()")
.getMany();
}
async getRemindersByUserId(userId: string): Promise<Reminder[]> {
return this.reminders.find({
where: {
guild_id: this.guildId,
user_id: userId,
},
});
}
find(id: number) {
return this.reminders.findOne({ id });
}
2019-02-20 00:01:14 +02:00
async delete(id) {
await this.reminders.delete({
guild_id: this.guildId,
id,
});
}
async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string) {
const result = await this.reminders.insert({
2019-02-20 00:01:14 +02:00
guild_id: this.guildId,
user_id: userId,
channel_id: channelId,
remind_at: remindAt,
body,
created_at,
2019-02-20 00:01:14 +02:00
});
return (await this.find(result.identifiers[0].id))!;
2019-02-20 00:01:14 +02:00
}
}