feat(api): add getNotificationHistory method for alert history
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
0da9ccf02d
commit
5483c8244c
@ -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<ApiResponse<NotificationHistoryResponse>> {
|
||||
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<NotificationSettings>): Promise<ApiResponse<NotificationSettings>> {
|
||||
const token = await this.getToken();
|
||||
|
||||
@ -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<string, unknown> | 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user