2023-07-01 12:17:45 +00:00
|
|
|
import { Repository } from "typeorm";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
2023-07-01 12:17:45 +00:00
|
|
|
import { dataSource } from "./dataSource";
|
2019-05-04 18:41:50 +03:00
|
|
|
import { ScheduledPost } from "./entities/ScheduledPost";
|
|
|
|
|
2019-05-25 21:25:34 +03:00
|
|
|
export class GuildScheduledPosts extends BaseGuildRepository {
|
2019-05-04 18:41:50 +03:00
|
|
|
private scheduledPosts: Repository<ScheduledPost>;
|
|
|
|
|
|
|
|
constructor(guildId) {
|
|
|
|
super(guildId);
|
2023-07-01 12:17:45 +00:00
|
|
|
this.scheduledPosts = dataSource.getRepository(ScheduledPost);
|
2019-05-04 18:41:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
all(): Promise<ScheduledPost[]> {
|
2021-09-11 19:06:51 +03:00
|
|
|
return this.scheduledPosts.createQueryBuilder().where("guild_id = :guildId", { guildId: this.guildId }).getMany();
|
2019-05-04 18:41:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getDueScheduledPosts(): Promise<ScheduledPost[]> {
|
|
|
|
return this.scheduledPosts
|
|
|
|
.createQueryBuilder()
|
|
|
|
.where("guild_id = :guildId", { guildId: this.guildId })
|
|
|
|
.andWhere("post_at <= NOW()")
|
|
|
|
.getMany();
|
|
|
|
}
|
|
|
|
|
2021-09-25 21:33:59 +03:00
|
|
|
find(id: number) {
|
2023-07-01 12:17:45 +00:00
|
|
|
return this.scheduledPosts.findOne({
|
|
|
|
where: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
});
|
2021-09-25 21:33:59 +03:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:41:50 +03:00
|
|
|
async delete(id) {
|
|
|
|
await this.scheduledPosts.delete({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async create(data: Partial<ScheduledPost>) {
|
2021-09-25 21:33:59 +03:00
|
|
|
const result = await this.scheduledPosts.insert({
|
2019-05-04 18:41:50 +03:00
|
|
|
...data,
|
|
|
|
guild_id: this.guildId,
|
|
|
|
});
|
2021-09-25 21:33:59 +03:00
|
|
|
|
|
|
|
return (await this.find(result.identifiers[0].id))!;
|
2019-05-04 18:41:50 +03:00
|
|
|
}
|
2019-12-01 23:23:34 +02:00
|
|
|
|
|
|
|
async update(id: number, data: Partial<ScheduledPost>) {
|
|
|
|
await this.scheduledPosts.update(id, data);
|
|
|
|
}
|
2019-05-04 18:41:50 +03:00
|
|
|
}
|