update schema and validation

This commit is contained in:
Alex Holliday committed 2025-06-18 14:42:59 +08:00
1 parent bb921690bf
commit 7bca60269c
2 files changed
+9 -39

No files matched your search

+1 -22
View File
@@ -1,19 +1,5 @@
import mongoose from "mongoose"; 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( const NotificationSchema = mongoose.Schema(
{ {
userId: { userId: {
@@ -30,14 +16,7 @@ const NotificationSchema = mongoose.Schema(
}, },
type: { type: {
type: String, type: String,
enum: ["email", "sms", "webhook", "pager_duty"], enum: ["email", "slack", "discord", "webhook", "pager_duty"],
},
platform: {
type: String,
},
config: {
type: configSchema,
default: () => ({}),
}, },
notificationName: { notificationName: {
type: String, type: String,
+8 -17
View File
@@ -570,24 +570,15 @@ const createNotificationBodyValidation = joi.object({
"string.email": "Please enter a valid e-mail address", "string.email": "Please enter a valid e-mail address",
}), }),
}), }),
type: joi.string().valid("email", "webhook", "pager_duty").required().messages({ type: joi
"string.empty": "Notification type is required", .string()
"any.required": "Notification type is required", .valid("email", "webhook", "slack", "discord", "pager_duty")
"any.only": "Notification type must be email, webhook, or pager_duty", .required()
}), .messages({
config: joi.when("type", { "string.empty": "Notification type is required",
is: "webhook", "any.required": "Notification type is required",
then: joi.object({ "any.only": "Notification type must be email, webhook, or pager_duty",
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",
}),
}), }),
}),
}); });
//**************************************** //****************************************