Add validation for updateTTL body
This commit is contained in:
1 parent
15e067c9bf
commit
9bbd5ce12a
5 files changed
+28
-8
No files matched your search
@@ -7,9 +7,10 @@ const {
|
|||||||
getTeamChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamIdParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
|
updateChecksTTLBodyValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const { successMessages } = require("../utils/messages");
|
const { successMessages } = require("../utils/messages");
|
||||||
const SERVICE_NAME = "check";
|
const SERVICE_NAME = "checkController";
|
||||||
|
|
||||||
const createCheck = async (req, res, next) => {
|
const createCheck = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
@@ -125,6 +126,7 @@ const deleteChecksByTeamId = async (req, res, next) => {
|
|||||||
error.method === undefined ? (error.method = "deleteChecksByTeam") : null;
|
error.method === undefined ? (error.method = "deleteChecksByTeam") : null;
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
next(error);
|
next(error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -143,7 +145,20 @@ const deleteChecksByTeamId = async (req, res, next) => {
|
|||||||
|
|
||||||
const updateChecksTTL = async (req, res, next) => {
|
const updateChecksTTL = async (req, res, next) => {
|
||||||
try {
|
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({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.CHECK_UPDATE_TTL,
|
msg: successMessages.CHECK_UPDATE_TTL,
|
||||||
|
|||||||
@@ -239,16 +239,16 @@ const deleteChecksByTeamId = async (teamId) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateChecksTTL = async (teamId) => {
|
const updateChecksTTL = async (teamId, ttl) => {
|
||||||
try {
|
try {
|
||||||
await Check.collection.dropIndex("expiry_1");
|
await Check.collection.dropIndex("expiry_1");
|
||||||
await Check.collection.createIndex(
|
await Check.collection.createIndex(
|
||||||
{ expiry: 1 }, // Field to index
|
{ expiry: 1 },
|
||||||
{ expireAfterSeconds: 60 } // TTL in seconds, adjust as necessary
|
{ expireAfterSeconds: ttl } // TTL in seconds, adjust as necessary
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = updateTTL;
|
error.method = "upddateChecksTTL";
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ const getMonitorStatsById = async (req) => {
|
|||||||
|
|
||||||
return monitorStats;
|
return monitorStats;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.methodName = "getMonitorStatsById";
|
error.method = "getMonitorStatsById";
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const handleErrors = (error, req, res, next) => {
|
|||||||
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
||||||
logger.error(error.message, {
|
logger.error(error.message, {
|
||||||
service: service,
|
service: service,
|
||||||
methodName: error.methodName,
|
method: error.method,
|
||||||
});
|
});
|
||||||
res.status(status).json({ success: false, msg: message });
|
res.status(status).json({ success: false, msg: message });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -335,6 +335,10 @@ const deleteChecksByTeamIdParamValidation = joi.object({
|
|||||||
teamId: joi.string().required(),
|
teamId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateChecksTTLBodyValidation = joi.object({
|
||||||
|
ttl: joi.number().required(),
|
||||||
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// PageSpeedCheckValidation
|
// PageSpeedCheckValidation
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -423,6 +427,7 @@ module.exports = {
|
|||||||
getTeamChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamIdParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
|
updateChecksTTLBodyValidation,
|
||||||
deleteUserParamValidation,
|
deleteUserParamValidation,
|
||||||
getPageSpeedCheckParamValidation,
|
getPageSpeedCheckParamValidation,
|
||||||
createPageSpeedCheckParamValidation,
|
createPageSpeedCheckParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user