mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-28 20:59:23 -06:00
Add db method for deleting checks by team
This commit is contained in:
@@ -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,33 @@ const deleteChecks = async (monitorId) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all checks for a team
|
||||
* @async
|
||||
* @param {string} monitorId
|
||||
* @returns {number}
|
||||
* @throws {Error}
|
||||
*/
|
||||
|
||||
const deleteChecksByTeam = async (teamId) => {
|
||||
try {
|
||||
const teamMonitors = await Monitor.find({ teamId: teamId });
|
||||
teamMonitors.forEach(async (monitor) => {
|
||||
await Check.deleteMany({ monitorId: monitor._id });
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createCheck,
|
||||
getChecksCount,
|
||||
getChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeam,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user