Files
dockhand/routes/api/notifications/[id]/test/+server.ts
Jarek Krochmalski 62e3c6439e Initial commit
2025-12-28 21:16:03 +01:00

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 });
}
};