Files
smoothschedule/frontend/src/api/notifications.ts
poduck 92724d03b6 refactor(api): Remove '/api' prefix from frontend API calls and config
- Removed '/api/' prefix from endpoint paths in auth.ts, notifications.ts, oauth.ts, and platform.ts to align with the backend URL reconfiguration.
- Updated 'API_BASE_URL' in config.ts to remove the '/api' suffix, ensuring that API requests are correctly routed to the root of the 'api' subdomain (e.g., http://api.lvh.me:8000/).
- Included improvements to login redirect logic in client.ts.
2025-12-01 01:48:22 -05:00

65 lines
1.7 KiB
TypeScript

import apiClient from './client';
export interface Notification {
id: number;
verb: string;
read: boolean;
timestamp: string;
data: Record<string, any>;
actor_type: string | null;
actor_display: string | null;
target_type: string | null;
target_display: string | null;
target_url: string | null;
}
export interface UnreadCountResponse {
count: number;
}
/**
* Get all notifications for the current user
*/
export const getNotifications = async (params?: { read?: boolean; limit?: number }): Promise<Notification[]> => {
const queryParams = new URLSearchParams();
if (params?.read !== undefined) {
queryParams.append('read', String(params.read));
}
if (params?.limit !== undefined) {
queryParams.append('limit', String(params.limit));
}
const query = queryParams.toString();
const url = query ? `/notifications/?${query}` : '/notifications/';
const response = await apiClient.get(url);
return response.data;
};
/**
* Get count of unread notifications
*/
export const getUnreadCount = async (): Promise<number> => {
const response = await apiClient.get<UnreadCountResponse>('/notifications/unread_count/');
return response.data.count;
};
/**
* Mark a single notification as read
*/
export const markNotificationRead = async (id: number): Promise<void> => {
await apiClient.post(`/notifications/${id}/mark_read/`);
};
/**
* Mark all notifications as read
*/
export const markAllNotificationsRead = async (): Promise<void> => {
await apiClient.post('/notifications/mark_all_read/');
};
/**
* Delete all read notifications
*/
export const clearAllNotifications = async (): Promise<void> => {
await apiClient.delete('/notifications/clear_all/');
};