mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-10 11:49:49 -06:00
Add validation for updateTTL body
This commit is contained in:
@@ -7,9 +7,10 @@ const {
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
updateChecksTTLBodyValidation,
|
||||
} = require("../validation/joi");
|
||||
const { successMessages } = require("../utils/messages");
|
||||
const SERVICE_NAME = "check";
|
||||
const SERVICE_NAME = "checkController";
|
||||
|
||||
const createCheck = async (req, res, next) => {
|
||||
try {
|
||||
@@ -125,6 +126,7 @@ const deleteChecksByTeamId = async (req, res, next) => {
|
||||
error.method === undefined ? (error.method = "deleteChecksByTeam") : null;
|
||||
error.status = 422;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -143,7 +145,20 @@ const deleteChecksByTeamId = async (req, res, next) => {
|
||||
|
||||
const updateChecksTTL = async (req, res, next) => {
|
||||
try {
|
||||
await req.db.updateChecksTTL(1);
|
||||
await updateChecksTTLBodyValidation.validateAsync(req.body);
|
||||
} catch (error) {
|
||||
error.status = 422;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "updateChecksTTL") : null;
|
||||
error.message =
|
||||
error.details?.[0]?.message || error.message || "Validation Error";
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const ttl = req.body.ttl;
|
||||
await req.db.updateChecksTTL(1, ttl);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.CHECK_UPDATE_TTL,
|
||||
|
||||
@@ -239,16 +239,16 @@ const deleteChecksByTeamId = async (teamId) => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateChecksTTL = async (teamId) => {
|
||||
const updateChecksTTL = async (teamId, ttl) => {
|
||||
try {
|
||||
await Check.collection.dropIndex("expiry_1");
|
||||
await Check.collection.createIndex(
|
||||
{ expiry: 1 }, // Field to index
|
||||
{ expireAfterSeconds: 60 } // TTL in seconds, adjust as necessary
|
||||
{ expiry: 1 },
|
||||
{ expireAfterSeconds: ttl } // TTL in seconds, adjust as necessary
|
||||
);
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = updateTTL;
|
||||
error.method = "upddateChecksTTL";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -262,7 +262,7 @@ const getMonitorStatsById = async (req) => {
|
||||
|
||||
return monitorStats;
|
||||
} catch (error) {
|
||||
error.methodName = "getMonitorStatsById";
|
||||
error.method = "getMonitorStatsById";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ const handleErrors = (error, req, res, next) => {
|
||||
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
||||
logger.error(error.message, {
|
||||
service: service,
|
||||
methodName: error.methodName,
|
||||
method: error.method,
|
||||
});
|
||||
res.status(status).json({ success: false, msg: message });
|
||||
};
|
||||
|
||||
@@ -335,6 +335,10 @@ const deleteChecksByTeamIdParamValidation = joi.object({
|
||||
teamId: joi.string().required(),
|
||||
});
|
||||
|
||||
const updateChecksTTLBodyValidation = joi.object({
|
||||
ttl: joi.number().required(),
|
||||
});
|
||||
|
||||
//****************************************
|
||||
// PageSpeedCheckValidation
|
||||
//****************************************
|
||||
@@ -423,6 +427,7 @@ module.exports = {
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
updateChecksTTLBodyValidation,
|
||||
deleteUserParamValidation,
|
||||
getPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckParamValidation,
|
||||
|
||||
Reference in New Issue
Block a user