From 7bca60269cc79eb8f56b6139e4877716cdd928e0 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Jun 2025 14:42:59 +0800 Subject: [PATCH] update schema and validation --- server/db/models/Notification.js | 23 +---------------------- server/validation/joi.js | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/server/db/models/Notification.js b/server/db/models/Notification.js index 751324131..fe314fc74 100755 --- a/server/db/models/Notification.js +++ b/server/db/models/Notification.js @@ -1,19 +1,5 @@ import mongoose from "mongoose"; -const configSchema = mongoose.Schema( - { - webhookUrl: { type: String }, - botToken: { type: String }, - chatId: { type: String }, - platform: { - type: String, - enum: ["slack", "pager_duty", "webhook", "discord"], - }, - routingKey: { type: String }, - }, - { _id: false } -); - const NotificationSchema = mongoose.Schema( { userId: { @@ -30,14 +16,7 @@ const NotificationSchema = mongoose.Schema( }, type: { type: String, - enum: ["email", "sms", "webhook", "pager_duty"], - }, - platform: { - type: String, - }, - config: { - type: configSchema, - default: () => ({}), + enum: ["email", "slack", "discord", "webhook", "pager_duty"], }, notificationName: { type: String, diff --git a/server/validation/joi.js b/server/validation/joi.js index e684cefa2..448a844f1 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -570,24 +570,15 @@ const createNotificationBodyValidation = joi.object({ "string.email": "Please enter a valid e-mail address", }), }), - type: joi.string().valid("email", "webhook", "pager_duty").required().messages({ - "string.empty": "Notification type is required", - "any.required": "Notification type is required", - "any.only": "Notification type must be email, webhook, or pager_duty", - }), - config: joi.when("type", { - is: "webhook", - then: joi.object({ - webhookUrl: joi.string().uri().required().messages({ - "string.uri": "Webhook URL must be a valid URI", - "any.required": "Webhook URL is required", - }), - platform: joi.string().required().messages({ - "string.empty": "Platform is required", - "any.required": "Platform is required", - }), + type: joi + .string() + .valid("email", "webhook", "slack", "discord", "pager_duty") + .required() + .messages({ + "string.empty": "Notification type is required", + "any.required": "Notification type is required", + "any.only": "Notification type must be email, webhook, or pager_duty", }), - }), }); //****************************************