remove old DB references

This commit is contained in:
Alex Holliday committed 2026-02-12 23:03:16 +00:00
1 parent f337ca5ff0
commit b6b1b8464c
3 files changed
+11 -6

No files matched your search

@@ -11,6 +11,7 @@ import type { LatestChecksMap } from "@/repositories/checks/MongoChecksRepistory
export interface IChecksRepository {
// create
create(check: Check): Promise<Check>;
createChecks(checks: Check[]): Promise<Check[]>;
// single fetch
@@ -227,6 +227,11 @@ class MongoChecksRepository implements IChecksRepository {
} as unknown as CheckDocument;
};
create = async (check: Check) => {
const savedCheck = await CheckModel.create(check);
return this.toEntity(savedCheck);
};
createChecks = async (checks: Check[]) => {
const docs = checks.map((check) => this.toDocument(check));
const inserted = await CheckModel.insertMany(docs);
@@ -52,7 +52,7 @@ export class StatusService implements IStatusService {
try {
const monitorId = monitor.id;
const { responseTime, status } = networkResponse;
let stats = await this.monitorStatsRepository.findByMonitorId(monitorId);
let stats: Omit<MonitorStats, "id" | "createdAt" | "updatedAt"> = await this.monitorStatsRepository.findByMonitorId(monitorId);
if (!stats) {
stats = {
monitorId,
@@ -62,6 +62,7 @@ export class StatusService implements IStatusService {
totalDownChecks: 0,
uptimePercentage: 0,
lastResponseTime: 0,
lastCheckTimestamp: 0,
};
}
@@ -105,8 +106,7 @@ export class StatusService implements IStatusService {
// latest check
stats.lastCheckTimestamp = new Date().getTime();
await stats.save();
await this.monitorStatsRepository.create(stats);
return true;
} catch (error: any) {
this.logger.error({
@@ -121,11 +121,10 @@ export class StatusService implements IStatusService {
handleIncidentForCheck = async (check: Check, monitor: Monitor, action: any, errorContext = "incident handling") => {
try {
let savedCheck;
let savedCheck: Check | null = null;
if (!check.id) {
try {
const checkModel = new CheckModel(check);
savedCheck = await checkModel.save();
savedCheck = await this.checksRepository.create(check);
this.buffer.removeCheckFromBuffer(check);
} catch (checkError: any) {