import { BaseRepository } from "./BaseRepository"; import { getRepository, Repository } from "typeorm"; import { ScheduledPost } from "./entities/ScheduledPost"; export class GuildScheduledPosts extends BaseRepository { private scheduledPosts: Repository; constructor(guildId) { super(guildId); this.scheduledPosts = getRepository(ScheduledPost); } all(): Promise { return this.scheduledPosts .createQueryBuilder() .where("guild_id = :guildId", { guildId: this.guildId }) .getMany(); } getDueScheduledPosts(): Promise { return this.scheduledPosts .createQueryBuilder() .where("guild_id = :guildId", { guildId: this.guildId }) .andWhere("post_at <= NOW()") .getMany(); } async delete(id) { await this.scheduledPosts.delete({ guild_id: this.guildId, id, }); } async create(data: Partial) { await this.scheduledPosts.insert({ ...data, guild_id: this.guildId, }); } }