Add db method for deleting checks by team
This commit is contained in:
1 parent
15defa33eb
commit
22770cc343
1 file changed
+24
-1
@@ -170,7 +170,7 @@ const getTeamChecks = async (req) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all checks for a user
|
* Delete all checks for a monitor
|
||||||
* @async
|
* @async
|
||||||
* @param {string} monitorId
|
* @param {string} monitorId
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
@@ -185,10 +185,33 @@ const deleteChecks = async (monitorId) => {
|
|||||||
throw error;
|
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 = {
|
module.exports = {
|
||||||
createCheck,
|
createCheck,
|
||||||
getChecksCount,
|
getChecksCount,
|
||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
|
deleteChecksByTeam,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user