remove monitors from status page on delete
This commit is contained in:
1 parent
cc8949538f
commit
4b621a228f
10 files changed
+47
-9
No files matched your search
@@ -3,6 +3,7 @@ import HardwareCheck from "./HardwareCheck.js";
|
||||
import PageSpeedCheck from "./PageSpeedCheck.js";
|
||||
import Check from "./Check.js";
|
||||
import MonitorStats from "./MonitorStats.js";
|
||||
import StatusPage from "./StatusPage.js";
|
||||
|
||||
const MonitorSchema = mongoose.Schema(
|
||||
{
|
||||
@@ -105,6 +106,9 @@ MonitorSchema.pre("findOneAndDelete", async function (next) {
|
||||
await Check.deleteMany({ monitorId: doc._id });
|
||||
}
|
||||
|
||||
// Deal with status pages
|
||||
await StatusPage.updateMany({ monitors: doc._id }, { $pull: { monitors: doc._id } });
|
||||
|
||||
await MonitorStats.deleteMany({ monitorId: doc._id.toString() });
|
||||
next();
|
||||
} catch (error) {
|
||||
|
||||
@@ -710,9 +710,11 @@ const deleteMonitor = async ({ monitorId }) => {
|
||||
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
|
||||
try {
|
||||
const monitor = await Monitor.findByIdAndDelete(monitorId);
|
||||
|
||||
if (!monitor) {
|
||||
throw new Error(stringService.getDbFindMonitorById(monitorId));
|
||||
}
|
||||
|
||||
return monitor;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
|
||||
@@ -106,7 +106,10 @@ const getStatusPage = async (url) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$monitors",
|
||||
$unwind: {
|
||||
path: "$monitors",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
@@ -153,9 +156,17 @@ const getStatusPage = async (url) => {
|
||||
url: 1,
|
||||
},
|
||||
monitors: {
|
||||
$sortArray: {
|
||||
input: "$monitors",
|
||||
sortBy: { orderIndex: 1 },
|
||||
$filter: {
|
||||
input: {
|
||||
$sortArray: {
|
||||
input: "$monitors",
|
||||
sortBy: { orderIndex: 1 },
|
||||
},
|
||||
},
|
||||
as: "monitor",
|
||||
cond: {
|
||||
$ne: ["$$monitor.orderIndex", -1],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user