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 {
|
try {
|
||||||
const globalPreferences = await globalPrefService.getGlobalPreferences();
|
const globalPreferences = await globalPrefService.getGlobalPreferences();
|
||||||
globalPreferences.webhooksPreferences.enabled = webhookPreferences.enabled;
|
|
||||||
|
|
||||||
if (webhookPreferences.url) {
|
// TODO: Validate the URL if webhooks are enabled by making a test request
|
||||||
globalPreferences.webhooksPreferences.url = webhookPreferences.url;
|
globalPreferences.webhooksPreferences = {
|
||||||
}
|
enabled: webhookPreferences.enabled,
|
||||||
|
url:
|
||||||
|
webhookPreferences.url === undefined
|
||||||
|
? globalPreferences.webhooksPreferences.url
|
||||||
|
: webhookPreferences.url
|
||||||
|
};
|
||||||
|
|
||||||
await globalPrefService.saveGlobalPreferences(globalPreferences);
|
await globalPrefService.saveGlobalPreferences(globalPreferences);
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,11 @@ import { rejectUnprocessableRequest } from '../../models/error.model.js';
|
|||||||
const WebhookPreferencesSchema: z.ZodType<WebhookPreferences> = z
|
const WebhookPreferencesSchema: z.ZodType<WebhookPreferences> = z
|
||||||
.object({
|
.object({
|
||||||
enabled: z.boolean(),
|
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(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user