Enhance routing and type definitions for new API endpoints. Added support for notifications and SSO routes, updated layout parameters, and improved type safety in route metadata. Refactored component imports for user and profile pages.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const PATCH: RequestHandler = async ({ params, request, locals }) => {
|
||||
if (!locals.user) {
|
||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
const id = params.id;
|
||||
if (!id) {
|
||||
return json({ error: 'Missing notification id' }, { status: 400 });
|
||||
}
|
||||
let body: { isRead?: boolean; isDeleted?: boolean } = {};
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
body = {};
|
||||
}
|
||||
try {
|
||||
const record = await locals.pb.collection('notifications').getOne(id);
|
||||
if ((record as Record<string, unknown>).user !== locals.user.id) {
|
||||
return json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
const updates: Record<string, boolean> = {};
|
||||
if (typeof body.isRead === 'boolean') updates.isRead = body.isRead;
|
||||
if (typeof body.isDeleted === 'boolean') updates.isDeleted = body.isDeleted;
|
||||
if (Object.keys(updates).length === 0) {
|
||||
return json({ error: 'No updates' }, { status: 400 });
|
||||
}
|
||||
await locals.pb.collection('notifications').update(id, updates);
|
||||
return json({ ok: true, ...updates });
|
||||
} catch {
|
||||
return json({ error: 'Notification not found or update failed' }, { status: 404 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user