backend: Update webhook preferences handling and validation logic
This commit is contained in:
parent
39b53f537d
commit
4cb9452ac1
@ -13,11 +13,15 @@ export const updateWebhookPreferences = async (req: Request, res: Response) => {
|
||||
|
||||
try {
|
||||
const globalPreferences = await globalPrefService.getGlobalPreferences();
|
||||
globalPreferences.webhooksPreferences.enabled = webhookPreferences.enabled;
|
||||
|
||||
if (webhookPreferences.url) {
|
||||
globalPreferences.webhooksPreferences.url = webhookPreferences.url;
|
||||
}
|
||||
// TODO: Validate the URL if webhooks are enabled by making a test request
|
||||
globalPreferences.webhooksPreferences = {
|
||||
enabled: webhookPreferences.enabled,
|
||||
url:
|
||||
webhookPreferences.url === undefined
|
||||
? globalPreferences.webhooksPreferences.url
|
||||
: webhookPreferences.url
|
||||
};
|
||||
|
||||
await globalPrefService.saveGlobalPreferences(globalPreferences);
|
||||
|
||||
|
||||
@ -15,7 +15,11 @@ import { rejectUnprocessableRequest } from '../../models/error.model.js';
|
||||
const WebhookPreferencesSchema: z.ZodType<WebhookPreferences> = z
|
||||
.object({
|
||||
enabled: z.boolean(),
|
||||
url: z.string().url().optional()
|
||||
url: z
|
||||
.string()
|
||||
.url('Must be a valid URL')
|
||||
.regex(/^https?:\/\//, { message: 'URL must start with http:// or https://' })
|
||||
.optional()
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user