42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
|
|
import WebClient from "@/shared/web-client"
|
||
|
|
|
||
|
|
export interface Device {
|
||
|
|
id: string
|
||
|
|
deviceId: string
|
||
|
|
status: "online" | "offline" | "upgrading"
|
||
|
|
lastHeartbeat: string
|
||
|
|
currentVersion?: string
|
||
|
|
targetVersion?: string
|
||
|
|
groupId?: string
|
||
|
|
createdAt: string
|
||
|
|
updatedAt: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface DevicesResponse {
|
||
|
|
data: Device[]
|
||
|
|
total: number
|
||
|
|
page: number
|
||
|
|
pageSize: number
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface DevicesQuery {
|
||
|
|
page?: number
|
||
|
|
pageSize?: number
|
||
|
|
status?: string
|
||
|
|
groupId?: string
|
||
|
|
search?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getDevices(query?: DevicesQuery): Promise<DevicesResponse> {
|
||
|
|
const params = new URLSearchParams()
|
||
|
|
if (query?.page) params.append("page", query.page.toString())
|
||
|
|
if (query?.pageSize) params.append("pageSize", query.pageSize.toString())
|
||
|
|
if (query?.status) params.append("status", query.status)
|
||
|
|
if (query?.groupId) params.append("groupId", query.groupId)
|
||
|
|
if (query?.search) params.append("search", query.search)
|
||
|
|
|
||
|
|
const queryString = params.toString()
|
||
|
|
const { data } = await WebClient.get<DevicesResponse>(`/devices${queryString ? `?${queryString}` : ""}`)
|
||
|
|
return data
|
||
|
|
}
|