final all done 2nd last plan before goign live

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-27 22:32:29 +00:00
parent 5f9a4b8dca
commit d0f98d35d6
19 changed files with 1581 additions and 233 deletions

View File

@@ -0,0 +1,106 @@
/**
* Notification API Service
* Fetches notifications from /api/v1/notifications/ endpoints
*/
import { fetchAPI } from './api';
// ============================================================================
// TYPES
// ============================================================================
export type NotificationTypeAPI = 'ai_task' | 'system' | 'credit' | 'billing' | 'integration' | 'content' | 'info';
export type NotificationSeverityAPI = 'info' | 'success' | 'warning' | 'error';
export interface NotificationAPI {
id: number;
notification_type: NotificationTypeAPI;
severity: NotificationSeverityAPI;
title: string;
message: string;
is_read: boolean;
created_at: string;
read_at: string | null;
action_label: string | null;
action_url: string | null;
metadata: Record<string, unknown> | null;
related_object_type: string | null;
related_object_id: number | null;
}
export interface NotificationListResponse {
count: number;
next: string | null;
previous: string | null;
results: NotificationAPI[];
}
export interface UnreadCountResponse {
unread_count: number;
}
// ============================================================================
// API FUNCTIONS
// ============================================================================
/**
* Fetch notifications list
*/
export async function fetchNotifications(params?: {
page?: number;
page_size?: number;
is_read?: boolean;
notification_type?: NotificationTypeAPI;
}): Promise<NotificationListResponse> {
const searchParams = new URLSearchParams();
if (params?.page) searchParams.set('page', params.page.toString());
if (params?.page_size) searchParams.set('page_size', params.page_size.toString());
if (params?.is_read !== undefined) searchParams.set('is_read', params.is_read.toString());
if (params?.notification_type) searchParams.set('notification_type', params.notification_type);
const queryString = searchParams.toString();
const url = `v1/notifications/${queryString ? `?${queryString}` : ''}`;
return fetchAPI(url);
}
/**
* Get unread notification count
*/
export async function fetchUnreadCount(): Promise<UnreadCountResponse> {
return fetchAPI('v1/notifications/unread-count/');
}
/**
* Mark a single notification as read
*/
export async function markNotificationRead(id: number): Promise<NotificationAPI> {
return fetchAPI(`v1/notifications/${id}/read/`, {
method: 'POST',
});
}
/**
* Mark all notifications as read
*/
export async function markAllNotificationsRead(): Promise<{ message: string; count: number }> {
return fetchAPI('v1/notifications/read-all/', {
method: 'POST',
});
}
/**
* Delete a notification
*/
export async function deleteNotification(id: number): Promise<void> {
await fetchAPI(`v1/notifications/${id}/`, {
method: 'DELETE',
});
}
/**
* Delete multiple notifications
*/
export async function deleteNotifications(ids: number[]): Promise<void> {
await Promise.all(ids.map(id => deleteNotification(id)));
}