Automated validation via joi.

This commit is contained in:
Skorpios committed 2025-02-12 18:54:34 -08:00
1 parent 023d9434c1
commit 012483d14f
3 files changed
+90 -37

No files matched your search

+2 -34
View File
@@ -6,53 +6,21 @@ class NotificationController {
}
async triggerNotification(req, res) {
const { monitorId, type, config } = req.body;
if (!monitorId || !type) {
return res.status(400).json({
success: false,
msg: "monitorId and type are required"
});
}
try {
const { monitorId, type, config } = req.body;
const networkResponse = {
monitor: { _id: monitorId, name: "Test Monitor", url: "http://www.google.com" },
status: false,
statusChanged: true,
prevStatus: true,
};
if (type === "webhook") {
if (!config?.type) {
return res.status(400).json({
success: false,
msg: "webhook type is required in config"
});
}
if (config.type === "telegram") {
if (!config.botToken || !config.chatId) {
return res.status(400).json({
success: false,
msg: "botToken and chatId are required for Telegram notifications"
});
}
} else if (["discord", "slack"].includes(config.type)) {
if (!config.webhookUrl) {
return res.status(400).json({
success: false,
msg: `webhookUrl is required for ${config.type} notifications`
});
}
}
await this.notificationService.sendWebhookNotification(
networkResponse,
config
);
}
res.json({ success: true, msg: "Notification sent successfully" });
} catch (error) {
logger.error({