zappyzep/src/data/GuildScheduledPosts.ts
Dragory d54897acdd Split BaseRepository into non-guild and guild
BaseRepository includes all the non-guild-specific functionality,
such as with() and getRelations().
BaseGuildRepository includes guild-specific functionality, such as
getInstance().
2019-05-25 21:25:34 +03:00

41 lines
1 KiB
TypeScript

import { BaseGuildRepository } from "./BaseGuildRepository";
import { getRepository, Repository } from "typeorm";
import { ScheduledPost } from "./entities/ScheduledPost";
export class GuildScheduledPosts extends BaseGuildRepository {
private scheduledPosts: Repository<ScheduledPost>;
constructor(guildId) {
super(guildId);
this.scheduledPosts = getRepository(ScheduledPost);
}
all(): Promise<ScheduledPost[]> {
return this.scheduledPosts
.createQueryBuilder()
.where("guild_id = :guildId", { guildId: this.guildId })
.getMany();
}
getDueScheduledPosts(): Promise<ScheduledPost[]> {
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<ScheduledPost>) {
await this.scheduledPosts.insert({
...data,
guild_id: this.guildId,
});
}
}