import { api } from './api'; import type { Notification } from '../types/notification.types'; async function unwrap( promise: ReturnType> ): Promise { const response = await promise; if (response.data?.data === undefined || response.data?.data === null) { throw new Error('Invalid API response'); } return response.data.data; } export const notificationsApi = { async getNotifications(): Promise { return unwrap(api.get<{ success: boolean; data: Notification[] }>('/api/notifications')); }, async getUnreadCount(): Promise { const data = await unwrap(api.get<{ success: boolean; data: { count: number } }>('/api/notifications/count')); return data.count; }, async markRead(id: string): Promise { await api.patch(`/api/notifications/${id}/read`); }, async markAllRead(): Promise { await api.post('/api/notifications/mark-all-read'); }, async dismissByType(quellTyp: string): Promise { await api.post('/api/notifications/dismiss-by-type', { quellTyp }); }, async deleteAllRead(): Promise { await api.delete('/api/notifications/read'); }, };