UPDATE
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/notifications'
|
||||
|
||||
export type NotificationLevel = 'info' | 'warning' | 'critical' | string
|
||||
|
||||
export interface NotificationItem {
|
||||
uuid: string
|
||||
farm_uuid: string
|
||||
since_id: number
|
||||
title: string
|
||||
message: string
|
||||
level: NotificationLevel
|
||||
is_read: boolean
|
||||
metadata?: Record<string, unknown> | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface NotificationsLongPollResponse {
|
||||
code: number
|
||||
msg: string
|
||||
data: NotificationItem[]
|
||||
}
|
||||
|
||||
export interface NotificationsListResponse {
|
||||
count: number
|
||||
next: string | null
|
||||
previous: string | null
|
||||
results?: {
|
||||
code: number
|
||||
msg: string
|
||||
data: NotificationItem[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface MarkNotificationsAsReadResponse {
|
||||
code: number
|
||||
msg: string
|
||||
marked_count: number
|
||||
}
|
||||
|
||||
export const notificationsService = {
|
||||
async longPoll(params: { farmUuid: string; sinceId?: number; timeout?: number }): Promise<NotificationItem[]> {
|
||||
const searchParams = new URLSearchParams({ farm_uuid: params.farmUuid })
|
||||
|
||||
if (typeof params.sinceId === 'number') {
|
||||
searchParams.set('since_id', String(params.sinceId))
|
||||
}
|
||||
|
||||
if (typeof params.timeout === 'number') {
|
||||
searchParams.set('timeout', String(params.timeout))
|
||||
}
|
||||
|
||||
const response = await apiClient.get<NotificationsLongPollResponse>(`${PREFIX}/long-poll/?${searchParams.toString()}`)
|
||||
|
||||
return Array.isArray(response.data) ? response.data : []
|
||||
},
|
||||
|
||||
async list(params: { farmUuid: string; page?: number; pageSize?: number }): Promise<NotificationsListResponse> {
|
||||
const searchParams = new URLSearchParams({ farm_uuid: params.farmUuid })
|
||||
|
||||
if (typeof params.page === 'number') {
|
||||
searchParams.set('page', String(params.page))
|
||||
}
|
||||
|
||||
if (typeof params.pageSize === 'number') {
|
||||
searchParams.set('page_size', String(params.pageSize))
|
||||
}
|
||||
|
||||
return apiClient.get<NotificationsListResponse>(`${PREFIX}/list/?${searchParams.toString()}`)
|
||||
},
|
||||
|
||||
async markAsRead(payload: { farmUuid: string; sliceId: number }): Promise<MarkNotificationsAsReadResponse> {
|
||||
return apiClient.post<MarkNotificationsAsReadResponse>(`${PREFIX}/mark-as-read/`, {
|
||||
farm_uuid: payload.farmUuid,
|
||||
slice_id: payload.sliceId
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user