mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-07 05:40:11 +00:00
Initial commit
This commit is contained in:
31
routes/api/notifications/[id]/test/+server.ts
Normal file
31
routes/api/notifications/[id]/test/+server.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user