Update delete all method
This commit is contained in:
1 parent
a89777333a
commit
3f5dc337a0
3 files changed
+18
-7
No files matched your search
@@ -368,10 +368,20 @@ const deleteMonitor = async (req, res, next) => {
|
|||||||
|
|
||||||
const deleteAllMonitors = async (req, res) => {
|
const deleteAllMonitors = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const deleteCount = await req.db.deleteAllMonitors();
|
const token = getTokenFromHeaders(req.headers);
|
||||||
|
const { teamId } = jwt.verify(token, process.env.JWT_SECRET);
|
||||||
|
const { monitors, deletedCount } = await req.db.deleteAllMonitors(teamId);
|
||||||
|
await monitors.forEach(async (monitor) => {
|
||||||
|
await req.jobQueue.deleteJob(monitor);
|
||||||
|
await req.db.deleteChecks(monitor._id);
|
||||||
|
await req.db.deleteAlertByMonitorId(monitor._id);
|
||||||
|
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
|
||||||
|
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
||||||
|
});
|
||||||
|
|
||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
.json({ success: true, msg: `Deleted ${deleteCount} monitors` });
|
.json({ success: true, msg: `Deleted ${deletedCount} monitors` });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
next(error);
|
next(error);
|
||||||
@@ -472,7 +482,6 @@ const pauseMonitor = async (req, res, next) => {
|
|||||||
const addDemoMonitors = async (req, res, next) => {
|
const addDemoMonitors = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const token = getTokenFromHeaders(req.headers);
|
const token = getTokenFromHeaders(req.headers);
|
||||||
// Get email from token
|
|
||||||
const { _id, teamId } = jwt.verify(token, process.env.JWT_SECRET);
|
const { _id, teamId } = jwt.verify(token, process.env.JWT_SECRET);
|
||||||
const demoMonitors = await req.db.addDemoMonitors(_id, teamId);
|
const demoMonitors = await req.db.addDemoMonitors(_id, teamId);
|
||||||
await demoMonitors.forEach(async (monitor) => {
|
await demoMonitors.forEach(async (monitor) => {
|
||||||
|
|||||||
@@ -451,10 +451,12 @@ const deleteMonitor = async (req, res) => {
|
|||||||
* DELETE ALL MONITORS (TEMP)
|
* DELETE ALL MONITORS (TEMP)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const deleteAllMonitors = async (req, res) => {
|
const deleteAllMonitors = async (teamId) => {
|
||||||
try {
|
try {
|
||||||
const deletedCount = await Monitor.deleteMany({});
|
const monitors = await Monitor.find({ teamId });
|
||||||
return deletedCount.deletedCount;
|
const { deletedCount } = await Monitor.deleteMany({ teamId });
|
||||||
|
|
||||||
|
return { monitors, deletedCount };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ router.put(
|
|||||||
);
|
);
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/all",
|
"/",
|
||||||
isAllowed(["superadmin"]),
|
isAllowed(["superadmin"]),
|
||||||
monitorController.deleteAllMonitors
|
monitorController.deleteAllMonitors
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user