cleanup incidents
This commit is contained in:
1 parent
0032765bd1
commit
cddf8b32e6
6 files changed
+25
-1
No files matched your search
@@ -13,7 +13,7 @@ import type {
|
||||
GotTimings,
|
||||
MonitorType,
|
||||
} from "@/types/index.js";
|
||||
import { CheckModel, type CheckDocument } from "@/db/models/index.js";
|
||||
import { CheckModel, MonitorModel, type CheckDocument } from "@/db/models/index.js";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const SERVICE_NAME = "StatusService";
|
||||
|
||||
@@ -24,5 +24,6 @@ export interface IIncidentsRepository {
|
||||
updateById(incidentId: string, teamId: string, updateData: Partial<Incident>): Promise<Incident>;
|
||||
// delete
|
||||
deleteByMonitorId(monitorId: string, teamId: string): Promise<number>;
|
||||
deleteByMonitorIdsNotIn(monitorIds: string[]): Promise<number>;
|
||||
// other
|
||||
}
|
||||
@@ -281,5 +281,11 @@ class MongoIncidentRepository implements IIncidentsRepository {
|
||||
});
|
||||
return result.deletedCount || 0;
|
||||
};
|
||||
|
||||
deleteByMonitorIdsNotIn = async (monitorIds: string[]): Promise<number> => {
|
||||
const objectIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const result = await IncidentModel.deleteMany({ monitorId: { $nin: objectIds } });
|
||||
return result.deletedCount ?? 0;
|
||||
};
|
||||
}
|
||||
export default MongoIncidentRepository;
|
||||
Reference in new issue
Block a user