Merge pull request #388 from bluewave-labs/feat/speedcheck-body
Updated validation schemas in the joi and changed validation schema in the controller for the page speed check.
This commit is contained in:
3 files changed
+37
-6
No files matched your search
@@ -4,6 +4,7 @@ const SERVICE_NAME = "pagespeed";
|
||||
const {
|
||||
getPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckBodyValidation,
|
||||
deletePageSpeedCheckParamValidation,
|
||||
} = require("../validation/joi");
|
||||
|
||||
@@ -42,7 +43,26 @@ const createPageSpeedCheck = async (req, res, next) => {
|
||||
// Validate monitorId parameter
|
||||
await createPageSpeedCheckParamValidation.validateAsync(req.params);
|
||||
|
||||
return res.status(200).json({ msg: "Hit createPageSpeedCheck" });
|
||||
// Validate request body
|
||||
await createPageSpeedCheckBodyValidation.validateAsync(req.body);
|
||||
|
||||
const { monitorId } = req.params;
|
||||
const { accessibility, bestPractices, seo, performance } = req.body;
|
||||
|
||||
const newPageSpeedCheck = new PageSpeedCheck({
|
||||
monitorId,
|
||||
accessibility,
|
||||
bestPractices,
|
||||
seo,
|
||||
performance,
|
||||
});
|
||||
|
||||
await newPageSpeedCheck.save();
|
||||
|
||||
return res.status(201).json({
|
||||
msg: successMessages.CREATED,
|
||||
data: newPageSpeedCheck,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.isJoi) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const router = require("express").Router();
|
||||
const { verifyOwnership } = require("../middleware/verifyOwnership");
|
||||
const Monitor = require("../models/Monitor");
|
||||
const { createPageSpeedCheck, getPageSpeedChecks, deletePageSpeedCheck } = require("../controllers/pageSpeedCheckController");
|
||||
|
||||
const checkController = require("../controllers/pageSpeedCheckController");
|
||||
|
||||
/**
|
||||
* @route POST /pagespeed/:monitorId
|
||||
@@ -14,7 +13,7 @@ const { createPageSpeedCheck, getPageSpeedChecks, deletePageSpeedCheck } = requi
|
||||
router.post(
|
||||
"/pagespeed/:monitorId",
|
||||
verifyOwnership(Monitor, "monitorId"),
|
||||
createPageSpeedCheck
|
||||
checkController.createPageSpeedCheck
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ router.post(
|
||||
router.get(
|
||||
"/pagespeed/:monitorId",
|
||||
verifyOwnership(Monitor, "monitorId"),
|
||||
getPageSpeedChecks
|
||||
checkController.getPageSpeedChecks
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,7 @@ router.get(
|
||||
router.delete(
|
||||
"/pagespeed/:monitorId",
|
||||
verifyOwnership(Monitor, "monitorId"),
|
||||
deletePageSpeedCheck
|
||||
checkController.deletePageSpeedCheck
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -182,14 +182,25 @@ const deleteChecksParamValidation = joi.object({
|
||||
//****************************************
|
||||
// PageSpeedCheckValidation
|
||||
//****************************************
|
||||
|
||||
const getPageSpeedCheckParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
//Validation schema for the monitorId parameter
|
||||
const createPageSpeedCheckParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
//Validation schema for the monitorId body
|
||||
const createPageSpeedCheckBodyValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
accessibility: joi.number().required().min(0).max(100),
|
||||
bestPractices: joi.number().required().min(0).max(100),
|
||||
seo: joi.number().required().min(0).max(100),
|
||||
performance: joi.number().required().min(0).max(100),
|
||||
});
|
||||
|
||||
const deletePageSpeedCheckParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
@@ -221,4 +232,5 @@ module.exports = {
|
||||
getPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckParamValidation,
|
||||
deletePageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckBodyValidation,
|
||||
};
|
||||
Reference in new issue
Block a user