2021-09-25 21:33:59 +03:00
|
|
|
import moment from "moment-timezone";
|
2023-07-01 12:17:45 +00:00
|
|
|
import { Repository } from "typeorm";
|
2021-09-25 21:33:59 +03:00
|
|
|
import { DBDateFormat } from "../utils";
|
2023-04-01 12:58:17 +01:00
|
|
|
import { BaseRepository } from "./BaseRepository";
|
2023-07-01 12:17:45 +00:00
|
|
|
import { dataSource } from "./dataSource";
|
2023-04-01 12:58:17 +01:00
|
|
|
import { ScheduledPost } from "./entities/ScheduledPost";
|
2021-09-25 21:33:59 +03:00
|
|
|
|
|
|
|
export class ScheduledPosts extends BaseRepository {
|
|
|
|
private scheduledPosts: Repository<ScheduledPost>;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2023-07-01 12:17:45 +00:00
|
|
|
this.scheduledPosts = dataSource.getRepository(ScheduledPost);
|
2021-09-25 21:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getScheduledPostsDueSoon(threshold: number): Promise<ScheduledPost[]> {
|
|
|
|
const thresholdDateStr = moment.utc().add(threshold, "ms").format(DBDateFormat);
|
|
|
|
return this.scheduledPosts.createQueryBuilder().andWhere("post_at <= :date", { date: thresholdDateStr }).getMany();
|
|
|
|
}
|
|
|
|
}
|