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/GuildReminders.ts
Dragory 1aceb55a87 Run prettier and check tslint on entire codebase
Mainly to run these checks for the recent pull requests.
2020-01-12 11:48:31 +02:00

47 lines
1.2 KiB
TypeScript

import { BaseGuildRepository } from "./BaseGuildRepository";
import { getRepository, Repository } from "typeorm";
import { Reminder } from "./entities/Reminder";
export class GuildReminders extends BaseGuildRepository {
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,
});
}
async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string) {
await this.reminders.insert({
guild_id: this.guildId,
user_id: userId,
channel_id: channelId,
remind_at: remindAt,
body,
created_at,
});
}
}