Merge pull request #761 from bluewave-labs/feat/clear-checks
Feat/clear checks, resolves #759
This commit is contained in:
9 files changed
+190
-31
No files matched your search
@@ -170,7 +170,7 @@ const getTeamChecks = async (req) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all checks for a user
|
||||
* Delete all checks for a monitor
|
||||
* @async
|
||||
* @param {string} monitorId
|
||||
* @returns {number}
|
||||
@@ -185,10 +185,40 @@ const deleteChecks = async (monitorId) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all checks for a team
|
||||
* @async
|
||||
* @param {string} monitorId
|
||||
* @returns {number}
|
||||
* @throws {Error}
|
||||
*/
|
||||
|
||||
const deleteChecksByTeamId = async (teamId) => {
|
||||
try {
|
||||
const teamMonitors = await Monitor.find({ teamId: teamId });
|
||||
let totalDeletedCount = 0;
|
||||
|
||||
await Promise.all(
|
||||
teamMonitors.map(async (monitor) => {
|
||||
const result = await Check.deleteMany({ monitorId: monitor._id });
|
||||
totalDeletedCount += result.deletedCount;
|
||||
monitor.status = true;
|
||||
await monitor.save();
|
||||
})
|
||||
);
|
||||
|
||||
return totalDeletedCount;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createCheck,
|
||||
getChecksCount,
|
||||
getChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeamId,
|
||||
};
|
||||
Reference in new issue
Block a user