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 logger = require("../utils/logger");
|
||||
require("dotenv").config();
|
||||
const { createAlertParamValidation } = require("../validation/joi");
|
||||
|
||||
const SERVICE_NAME = "alerts";
|
||||
|
||||
const createAlert = (req, res, next) => {
|
||||
res.status(200).json({ success: true, msg: "Create Alert" });
|
||||
const createAlert = async (req, res, next) => {
|
||||
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) => {
|
||||
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) => {
|
||||
res.status(200).json({ success: true, msg: "Get Alerts By MonitorID" });
|
||||
|
||||
@@ -39,6 +39,10 @@ const editUserBodyValidation = joi.object({
|
||||
profilePicUrl: joi.string(),
|
||||
});
|
||||
|
||||
const createAlertParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
loginValidation,
|
||||
registerValidation,
|
||||
@@ -47,4 +51,5 @@ module.exports = {
|
||||
monitorValidation,
|
||||
editUserParamValidation,
|
||||
editUserBodyValidation,
|
||||
createAlertParamValidation,
|
||||
};
|
||||
Reference in new issue
Block a user