Add validation to createAlert
This commit is contained in:
1 parent
7e9f8d9d29
commit
e90073da24
2 files changed
+21
-3
No files matched your search
@@ -2,14 +2,27 @@ const express = require("express");
|
|||||||
const {} = require("../validation/joi");
|
const {} = require("../validation/joi");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
const { createAlertParamValidation } = require("../validation/joi");
|
||||||
|
|
||||||
const SERVICE_NAME = "alerts";
|
const SERVICE_NAME = "alerts";
|
||||||
|
|
||||||
const createAlert = (req, res, next) => {
|
const createAlert = async (req, res, next) => {
|
||||||
res.status(200).json({ success: true, msg: "Create Alert" });
|
try {
|
||||||
|
await createAlertParamValidation.validateAsync(req.params);
|
||||||
|
res
|
||||||
|
.status(200)
|
||||||
|
.json({ success: true, msg: "Create Alert", data: req.params.monitorId });
|
||||||
|
} catch (error) {
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const getAlertsByUserId = (req, res, next) => {
|
const getAlertsByUserId = (req, res, next) => {
|
||||||
res.status(200).json({ success: true, msg: "Get Alerts By UserID" });
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: "Get Alerts By UserID",
|
||||||
|
data: req.params.userId,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const getAlertsByMonitorId = (req, res, next) => {
|
const getAlertsByMonitorId = (req, res, next) => {
|
||||||
res.status(200).json({ success: true, msg: "Get Alerts By MonitorID" });
|
res.status(200).json({ success: true, msg: "Get Alerts By MonitorID" });
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ const editUserBodyValidation = joi.object({
|
|||||||
profilePicUrl: joi.string(),
|
profilePicUrl: joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createAlertParamValidation = joi.object({
|
||||||
|
monitorId: joi.string().required(),
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
loginValidation,
|
loginValidation,
|
||||||
registerValidation,
|
registerValidation,
|
||||||
@@ -47,4 +51,5 @@ module.exports = {
|
|||||||
monitorValidation,
|
monitorValidation,
|
||||||
editUserParamValidation,
|
editUserParamValidation,
|
||||||
editUserBodyValidation,
|
editUserBodyValidation,
|
||||||
|
createAlertParamValidation,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user