handle paused status
This commit is contained in:
1 parent
fbfb861447
commit
3abacb046b
4 files changed
+21
-17
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { type MonitorType, type Monitor, type MonitorsSummary, CheckSnapshot } from "@/types/index.js";
|
||||
import { type MonitorType, type Monitor, type MonitorStatus, type MonitorsSummary, CheckSnapshot } from "@/types/index.js";
|
||||
|
||||
export interface TeamQueryConfig {
|
||||
limit?: number;
|
||||
@@ -31,7 +31,7 @@ export interface IMonitorsRepository {
|
||||
|
||||
// update
|
||||
updateById(monitorId: string, teamId: string, updates: Partial<Monitor>): Promise<Monitor>;
|
||||
updateByIds(monitorIds: string[], teamId: string, updates: Partial<Monitor>): Promise<number>;
|
||||
updateByIds(monitorIds: string[], teamId: string, updates: Partial<Monitor>, excludeStatuses?: MonitorStatus[]): Promise<number>;
|
||||
updateStatusWindowAndChecks(
|
||||
monitorId: string,
|
||||
teamId: string,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MonitorModel } from "@/db/models/index.js";
|
||||
import type { MonitorDocument, CheckSnapshotDocument } from "@/db/models/index.js";
|
||||
import type { Monitor, MonitorsSummary, CheckSnapshot } from "@/types/index.js";
|
||||
import type { Monitor, MonitorStatus, MonitorsSummary, CheckSnapshot } from "@/types/index.js";
|
||||
import mongoose, { type FilterQuery, type PipelineStage } from "mongoose";
|
||||
import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js";
|
||||
import { MongoBulkWriteError } from "mongodb";
|
||||
@@ -190,9 +190,13 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
return this.toEntity(updatedMonitor);
|
||||
};
|
||||
|
||||
updateByIds = async (monitorIds: string[], teamId: string, updates: Partial<Monitor>) => {
|
||||
updateByIds = async (monitorIds: string[], teamId: string, updates: Partial<Monitor>, excludeStatuses?: MonitorStatus[]) => {
|
||||
const objectIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const updated = await MonitorModel.updateMany({ _id: { $in: objectIds }, teamId }, { $set: updates }, { runValidators: true });
|
||||
const filter: Record<string, unknown> = { _id: { $in: objectIds }, teamId };
|
||||
if (excludeStatuses && excludeStatuses.length > 0) {
|
||||
filter.status = { $nin: excludeStatuses };
|
||||
}
|
||||
const updated = await MonitorModel.updateMany(filter, { $set: updates }, { runValidators: true });
|
||||
return updated.modifiedCount;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user