remove mongo middleware

This commit is contained in:
Alex Holliday committed 2026-01-15 19:36:41 +00:00
1 parent 74a7f0a701
commit 68559741ba
19 files changed
+247 -141

No files matched your search

@@ -54,6 +54,9 @@ export interface UptimeChecksResult {
}
export interface IChecksRepository {
// create
// single fetch
// collection fetch
findLatestChecksByMonitorIds(monitorIds: string[], options?: { limitPerMonitor?: number }): Promise<LatestChecksMap>;
findDateRangeChecksByMonitor(
monitorId: string,
@@ -62,4 +65,7 @@ export interface IChecksRepository {
dateString: string,
options?: { type?: MonitorType }
): Promise<UptimeChecksResult | HardwareChecksResult | PageSpeedChecksResult>;
// update
//delete
deleteByMonitorId(monitorId: string): Promise<number>;
}
@@ -385,6 +385,11 @@ class MongoChecksRepository implements IChecksRepository {
checks: checks.map((doc) => this.toEntity(doc)),
};
};
deleteByMonitorId = async (monitorId: string): Promise<number> => {
const result = await CheckModel.deleteMany({ "metadata.monitorId": monitorId });
return result.deletedCount;
};
}
export default MongoChecksRepository;
+3
View File
@@ -6,3 +6,6 @@ export { default as MongoChecksRepository } from "@/repositories/checks/MongoChe
export * from "@/repositories/monitor-stats/IMonitorStatsRepository.js";
export { default as MongoMonitorStatsRepository } from "@/repositories/monitor-stats/MongoMonitorStatsRepository.js";
export * from "@/repositories/status-pages/IStatusPagesRepository.js";
export { default as MongoStatusPagesRepository } from "@/repositories/status-pages/MongoStatusPagesRepository.js";
@@ -5,5 +5,6 @@ export interface IMonitorStatsRepository {
findByMonitorId(monitorId: string): Promise<MonitorStats>;
// update
// delete
deleteByMonitorId(monitorId: string): Promise<MonitorStats>;
// other
}
@@ -39,6 +39,14 @@ class MongoMonitorStatsRepository implements IMonitorStatsRepository {
}
return this.toEntity(monitorStats);
};
deleteByMonitorId = async (monitorId: string) => {
const deleted = await MonitorStatsModel.findOneAndDelete({ monitorId: new mongoose.Types.ObjectId(monitorId) });
if (!deleted) {
throw new AppError({ message: "Monitor stats not found", status: 404 });
}
return this.toEntity(deleted);
};
}
export default MongoMonitorStatsRepository;
@@ -1,6 +1,6 @@
import { MonitorModel } from "@/db/models/index.js";
import type { MonitorDocument } from "@/db/models/index.js";
import type { Monitor, MonitorType } from "@/types/index.js";
import type { Monitor } from "@/types/index.js";
import mongoose, { type FilterQuery } from "mongoose";
import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js";
import { AppError } from "@/utils/AppError.js";
@@ -0,0 +1,11 @@
import type { StatusPage } from "@/types/statusPage.js";
export interface IStatusPagesRepository {
// create
// single fetch
// collection fetch
// update
// delete
// other
removeMonitorFromStatusPages(monitorId: string): Promise<number>;
}
@@ -0,0 +1,52 @@
import { IStatusPagesRepository } from "@/repositories/index.js";
import { type StatusPageDocument, StatusPageModel } from "@/db/models/StatusPage.js";
import type { StatusPage } from "@/types/statusPage.js";
import mongoose from "mongoose";
class MongoStatusPagesRepository implements IStatusPagesRepository {
private toEntity(doc: StatusPageDocument): StatusPage {
const toStringId = (value: unknown): string => {
if (value instanceof mongoose.Types.ObjectId) {
return value.toString();
}
return value?.toString() ?? "";
};
const toDateString = (value: Date | string): string => {
return value instanceof Date ? value.toISOString() : value;
};
const mapIdArray = (values?: mongoose.Types.ObjectId[]): string[] => {
return values?.map((value) => toStringId(value)) ?? [];
};
return {
id: toStringId(doc._id),
userId: toStringId(doc.userId),
teamId: toStringId(doc.teamId),
type: doc.type,
companyName: doc.companyName,
url: doc.url,
timezone: doc.timezone ?? undefined,
color: doc.color,
monitors: mapIdArray(doc.monitors),
subMonitors: mapIdArray(doc.subMonitors),
originalMonitors: doc.originalMonitors?.map((value) => toStringId(value)),
logo: doc.logo ?? undefined,
isPublished: doc.isPublished,
showCharts: doc.showCharts,
showUptimePercentage: doc.showUptimePercentage,
showAdminLoginLink: doc.showAdminLoginLink,
customCSS: doc.customCSS,
createdAt: toDateString(doc.createdAt),
updatedAt: toDateString(doc.updatedAt),
};
}
removeMonitorFromStatusPages = async (monitorId: string): Promise<number> => {
const res = await StatusPageModel.updateMany({ monitors: monitorId }, { $pull: { monitors: monitorId } });
return res.modifiedCount;
};
}
export default MongoStatusPagesRepository;