Fix jwt-token
This commit is contained in:
@@ -18,7 +18,7 @@ const alertRuleSchema = Joi.object({
|
||||
min_detections: Joi.number().integer().min(1).default(1),
|
||||
cooldown_period: Joi.number().integer().min(0).default(600),
|
||||
alert_channels: Joi.array().items(Joi.string().valid('sms', 'email', 'webhook')).default(['sms']),
|
||||
webhook_url: Joi.string().uri().optional(),
|
||||
webhook_url: Joi.string().uri().allow('').optional(),
|
||||
active_hours: Joi.object({
|
||||
start: Joi.string().pattern(/^\d{2}:\d{2}$/).optional(),
|
||||
end: Joi.string().pattern(/^\d{2}:\d{2}$/).optional()
|
||||
@@ -66,6 +66,21 @@ router.get('/rules', authenticateToken, async (req, res) => {
|
||||
// POST /api/alerts/rules - Create new alert rule
|
||||
router.post('/rules', authenticateToken, validateRequest(alertRuleSchema), async (req, res) => {
|
||||
try {
|
||||
// Custom validation for webhook URL when webhook channel is selected
|
||||
if (req.body.alert_channels && req.body.alert_channels.includes('webhook')) {
|
||||
if (!req.body.webhook_url || req.body.webhook_url.trim() === '') {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'Validation error',
|
||||
errors: [{
|
||||
field: 'webhook_url',
|
||||
message: 'Webhook URL is required when webhook channel is selected',
|
||||
value: req.body.webhook_url || ''
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const alertRule = await AlertRule.create({
|
||||
...req.body,
|
||||
user_id: req.user.id
|
||||
|
||||
Reference in New Issue
Block a user