2019-02-20 00:01:14 +02:00
|
|
|
import { getRepository, Repository } from "typeorm";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
2019-02-20 00:01:14 +02:00
|
|
|
import { Reminder } from "./entities/Reminder";
|
|
|
|
|
2019-05-25 21:25:34 +03:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(id) {
|
|
|
|
await this.reminders.delete({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-08 14:29:49 +11:00
|
|
|
async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string) {
|
2019-02-20 00:01:14 +02:00
|
|
|
await this.reminders.insert({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
user_id: userId,
|
|
|
|
channel_id: channelId,
|
|
|
|
remind_at: remindAt,
|
|
|
|
body,
|
2020-01-12 11:47:54 +02:00
|
|
|
created_at,
|
2019-02-20 00:01:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|