replace findAll with findAllForScheduling
This commit is contained in:
1 parent
4c8342f379
commit
5fa74bd883
7 files changed
+47
-23
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { MonitorType, Monitor, MonitorStatus, MonitorsSummary, CheckSnapshot } from "@/domain/monitors/monitor.type.js";
|
||||
import type { MonitorType, Monitor, MonitorStatus, MonitorsSummary, CheckSnapshot, MonitorScheduleFields } from "@/domain/monitors/monitor.type.js";
|
||||
|
||||
export interface TeamQueryConfig {
|
||||
limit?: number;
|
||||
@@ -26,7 +26,7 @@ export interface IMonitorsRepository {
|
||||
findByIdLean(monitorId: string): Promise<Monitor | null>;
|
||||
|
||||
// collection fetch
|
||||
findAll(): Promise<Monitor[]>;
|
||||
findAllForScheduling(): Promise<MonitorScheduleFields[]>;
|
||||
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[]>;
|
||||
findByTeamIdWithStats(teamId: string, config: TeamQueryConfig): Promise<Monitor[]>;
|
||||
findByIds(monitorIds: string[]): Promise<Monitor[]>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MonitorModel } from "@/domain/monitors/monitor.model.js";
|
||||
import type { MonitorDocument, CheckSnapshotDocument } from "@/domain/monitors/monitor.model.js";
|
||||
import type { CheckSnapshot } from "@/domain/checks/check.type.js";
|
||||
import type { Monitor, MonitorStatus, MonitorsSummary } from "@/domain/monitors/monitor.type.js";
|
||||
import type { Monitor, MonitorScheduleFields, MonitorStatus, MonitorsSummary } from "@/domain/monitors/monitor.type.js";
|
||||
import mongoose, { type FilterQuery, type PipelineStage } from "mongoose";
|
||||
import { MongoBulkWriteError } from "mongodb";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
@@ -41,13 +41,20 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
};
|
||||
|
||||
findByIdLean = async (monitorId: string): Promise<Monitor | null> => {
|
||||
const monitor = await MonitorModel.findOne({ _id: monitorId });
|
||||
const monitor = await MonitorModel.findOne({ _id: monitorId }).select({ recentChecks: 0 });
|
||||
return monitor ? this.toEntity(monitor) : null;
|
||||
};
|
||||
|
||||
findAll = async (): Promise<Monitor[]> => {
|
||||
const monitors = await MonitorModel.find();
|
||||
return this.mapDocuments(monitors);
|
||||
findAllForScheduling = async (): Promise<MonitorScheduleFields[]> => {
|
||||
const docs = await MonitorModel.find({}, { type: 1, isActive: 1, interval: 1, geoCheckEnabled: 1, geoCheckInterval: 1 }).lean();
|
||||
return docs.map((doc) => ({
|
||||
id: doc._id.toString(),
|
||||
type: doc.type,
|
||||
isActive: doc.isActive,
|
||||
interval: doc.interval,
|
||||
geoCheckEnabled: doc.geoCheckEnabled ?? false,
|
||||
geoCheckInterval: doc.geoCheckInterval ?? 300000,
|
||||
}));
|
||||
};
|
||||
|
||||
private queryBuilder = (config: TeamQueryConfig, teamId: string): FilterQuery<MonitorDocument> => {
|
||||
@@ -182,7 +189,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
},
|
||||
...(statusPatch && { $set: statusPatch }),
|
||||
},
|
||||
{ returnDocument: "after" }
|
||||
{ returnDocument: "after", projection: { recentChecks: 0 } }
|
||||
);
|
||||
|
||||
if (!updatedMonitor) {
|
||||
|
||||
@@ -178,3 +178,5 @@ export interface Game {
|
||||
}
|
||||
|
||||
export type GamesMap = Record<string, Game>;
|
||||
|
||||
export type MonitorScheduleFields = Pick<Monitor, "id" | "type" | "isActive" | "interval" | "geoCheckEnabled" | "geoCheckInterval">;
|
||||
Reference in new issue
Block a user