Files
Checkmate/Server/db/mongo/modules/checkModule.js
Alexander Holliday e47d3685ce Moved all methods to modules (#460)
* Moved all methods to modules

* removed old mongoDB file
2024-07-26 18:25:20 -07:00

59 lines
1.2 KiB
JavaScript

const Check = require("../../../models/Check");
/**
* Create a check for a monitor
* @async
* @param {Object} checkData
* @param {string} checkData.monitorId
* @param {boolean} checkData.status
* @param {number} checkData.responseTime
* @param {number} checkData.statusCode
* @param {string} checkData.message
* @returns {Promise<Check>}
* @throws {Error}
*/
const createCheck = async (checkData) => {
try {
const check = await new Check({ ...checkData }).save();
return check;
} catch (error) {
throw error;
}
};
/**
* Get all checks for a monitor
* @async
* @param {string} monitorId
* @returns {Promise<Array<Check>>}
* @throws {Error}
*/
const getChecks = async (monitorId) => {
try {
const checks = await Check.find({ monitorId });
return checks;
} catch (error) {
throw error;
}
};
/**
* Delete all checks for a monitor
* @async
* @param {string} monitorId
* @returns {number}
* @throws {Error}
*/
const deleteChecks = async (monitorId) => {
try {
const result = await Check.deleteMany({ monitorId });
return result.deletedCount;
} catch (error) {
throw error;
}
};
module.exports = { createCheck, getChecks, deleteChecks };