From 22770cc343d67599ed11d37c4e9ac0b3aa4c458b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 30 Aug 2024 09:41:27 -0700 Subject: [PATCH] Add db method for deleting checks by team --- Server/db/mongo/modules/checkModule.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index 56a40d2ad..89d0e707f 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -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, };