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/GuildScheduledPosts.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

import { getRepository, Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
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[]> {
2021-09-11 19:06:51 +03:00
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,
});
}
2019-12-01 23:23:34 +02:00
async update(id: number, data: Partial<ScheduledPost>) {
await this.scheduledPosts.update(id, data);
}
}