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 { VCAlert } from "./entities/VCAlert";
|
2021-09-25 21:33:59 +03:00
|
|
|
|
|
|
|
export class VCAlerts extends BaseRepository {
|
|
|
|
private allAlerts: Repository<VCAlert>;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2023-07-01 12:17:45 +00:00
|
|
|
this.allAlerts = dataSource.getRepository(VCAlert);
|
2021-09-25 21:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async getSoonExpiringAlerts(threshold: number): Promise<VCAlert[]> {
|
|
|
|
const thresholdDateStr = moment.utc().add(threshold, "ms").format(DBDateFormat);
|
|
|
|
return this.allAlerts.createQueryBuilder().andWhere("expires_at <= :date", { date: thresholdDateStr }).getMany();
|
|
|
|
}
|
|
|
|
}
|