mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-04 05:29:06 +00:00
32 lines
925 B
TypeScript
32 lines
925 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { getNotificationSetting } from '$lib/server/db';
|
|
import { testNotification } from '$lib/server/notifications';
|
|
import type { RequestHandler } from './$types';
|
|
|
|
export const POST: RequestHandler = async ({ params }) => {
|
|
try {
|
|
const id = parseInt(params.id);
|
|
if (isNaN(id)) {
|
|
return json({ error: 'Invalid ID' }, { status: 400 });
|
|
}
|
|
|
|
const setting = await getNotificationSetting(id);
|
|
if (!setting) {
|
|
return json({ error: 'Notification setting not found' }, { status: 404 });
|
|
}
|
|
|
|
const success = await testNotification(setting);
|
|
|
|
return json({
|
|
success,
|
|
message: success ? 'Test notification sent successfully' : 'Failed to send test notification'
|
|
});
|
|
} catch (error: any) {
|
|
console.error('Error testing notification:', error);
|
|
return json({
|
|
success: false,
|
|
error: error.message || 'Failed to test notification'
|
|
}, { status: 500 });
|
|
}
|
|
};
|