Files
HartOMat/frontend/src/api/notifications.ts
T
Hartmut 596360e507 refactor(section-d): frontend API client type safety audit
All 19 api/*.ts files already used import api from './client' (X-Tenant-ID
guaranteed). Fixed missing type generics and any usage in 10 files:
- worker.ts: args: any[] → unknown[]
- imports.ts, notifications.ts: add response type generics
- renderTemplates.ts: add typed generics on 6 calls
- materials.ts, cad.ts: type previously untyped api calls
- products.ts: ProductCadUploadResponse interface, typed generics
- uploads.ts: StepUploadResponse interface
- billing.ts, orders.ts: <Blob> on download calls

Zero bare axios usage, zero as any in API layer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 20:36:48 +01:00

83 lines
2.4 KiB
TypeScript

import api from './client'
export type NotificationChannel = 'notification' | 'activity' | 'alert'
export interface Notification {
id: string
action: string
entity_type: string | null
entity_id: string | null
details: Record<string, unknown> | null
timestamp: string
read_at: string | null
channel?: NotificationChannel
}
export interface NotificationListResponse {
items: Notification[]
unread_count: number
total: number
}
export async function getNotifications(params?: {
limit?: number
offset?: number
unread_only?: boolean
channel?: NotificationChannel
}): Promise<NotificationListResponse> {
const { data } = await api.get<NotificationListResponse>('/notifications', { params })
return data
}
export async function getUnreadCount(): Promise<number> {
const { data } = await api.get<{ unread_count: number }>('/notifications/unread-count')
return data.unread_count
}
export async function markAsRead(ids?: string[]): Promise<void> {
await api.post('/notifications/mark-read', { notification_ids: ids ?? null })
}
export async function markOneAsRead(id: string): Promise<void> {
await api.post(`/notifications/${id}/mark-read`)
}
// ── Notification Config ───────────────────────────────────────────────────
export type NotificationFrequency = 'immediate' | 'daily' | 'never'
export interface NotificationConfig {
id: string
user_id: string
event_type: string
channel: 'in_app' | 'email'
enabled: boolean
frequency: NotificationFrequency
created_at: string
}
export async function getNotificationConfigs(): Promise<NotificationConfig[]> {
const res = await api.get<NotificationConfig[]>('/notifications/config')
return res.data
}
export async function updateNotificationConfig(
eventType: string,
channel: string,
enabled: boolean,
frequency?: NotificationFrequency
): Promise<NotificationConfig> {
const body: Record<string, unknown> = { enabled }
if (frequency !== undefined) body.frequency = frequency
const res = await api.put<NotificationConfig>(
`/notifications/config/${encodeURIComponent(eventType)}/${channel}`,
body
)
return res.data
}
export async function resetNotificationConfigs(): Promise<NotificationConfig[]> {
const res = await api.post<NotificationConfig[]>('/notifications/config/reset')
return res.data
}