From 5483c8244c2ae82455bf884eea17f46b5ed0313a Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 26 Jan 2026 18:41:36 -0800 Subject: [PATCH] feat(api): add getNotificationHistory method for alert history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add NotificationHistoryItem, NotificationHistoryResponse types - Add notification type enums (NotificationType, NotificationChannel, NotificationStatus) - Implement getNotificationHistory() in api.ts with filtering support - Supports limit, offset, type, status query params - Returns paginated history with total count 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- services/api.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- types/index.ts | 29 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/services/api.ts b/services/api.ts index a57f8a7..5ae1255 100644 --- a/services/api.ts +++ b/services/api.ts @@ -1,4 +1,4 @@ -import type { ApiError, ApiResponse, AuthResponse, Beneficiary, BeneficiaryDashboardData, ChatResponse, DashboardSingleResponse, NotificationSettings, WPSensor } from '@/types'; +import type { ApiError, ApiResponse, AuthResponse, Beneficiary, BeneficiaryDashboardData, ChatResponse, DashboardSingleResponse, NotificationHistoryResponse, NotificationSettings, WPSensor } from '@/types'; import { File } from 'expo-file-system'; import * as SecureStore from 'expo-secure-store'; import AsyncStorage from '@react-native-async-storage/async-storage'; @@ -1416,6 +1416,54 @@ class ApiService { } } + // Get notification history for current user + async getNotificationHistory(options?: { + limit?: number; + offset?: number; + type?: string; + status?: string; + }): Promise> { + const token = await this.getToken(); + if (!token) { + return { ok: false, error: { message: 'Not authenticated', code: 'UNAUTHORIZED' } }; + } + + try { + // Build query params + const params = new URLSearchParams(); + if (options?.limit) params.append('limit', String(options.limit)); + if (options?.offset) params.append('offset', String(options.offset)); + if (options?.type) params.append('type', options.type); + if (options?.status) params.append('status', options.status); + + const queryString = params.toString(); + const url = `${WELLNUO_API_URL}/notification-settings/history${queryString ? `?${queryString}` : ''}`; + + const response = await fetch(url, { + method: 'GET', + headers: { + 'Authorization': `Bearer ${token}`, + }, + }); + + const data = await response.json(); + + if (response.ok) { + return { data, ok: true }; + } + + return { + ok: false, + error: { message: data.error || 'Failed to get notification history' }, + }; + } catch (error) { + return { + ok: false, + error: { message: 'Network error. Please check your connection.' }, + }; + } + } + // Update notification settings for current user async updateNotificationSettings(settings: Partial): Promise> { const token = await this.getToken(); diff --git a/types/index.ts b/types/index.ts index 7815dcd..6e9cfdd 100644 --- a/types/index.ts +++ b/types/index.ts @@ -179,6 +179,35 @@ export interface ChatResponse { status: string; } +// Notification Types +export type NotificationType = 'emergency' | 'activity' | 'low_battery' | 'daily_summary' | 'weekly_summary' | 'system'; +export type NotificationChannel = 'push' | 'email' | 'sms'; +export type NotificationStatus = 'pending' | 'sent' | 'delivered' | 'failed' | 'skipped'; + +// Notification History Item (from /api/notification-settings/history) +export interface NotificationHistoryItem { + id: number; + title: string; + body: string; + type: NotificationType; + channel: NotificationChannel; + status: NotificationStatus; + skipReason: string | null; + data: Record | null; + beneficiaryId: number | null; + createdAt: string; + sentAt: string | null; + deliveredAt: string | null; +} + +// Notification History Response +export interface NotificationHistoryResponse { + history: NotificationHistoryItem[]; + total: number; + limit: number; + offset: number; +} + // Notification Settings export interface NotificationSettings { // Alert types