mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-05 16:00:21 +08:00
后端返回 null (Go nil slice) 时前端访问 .length 抛出 TypeError, 在 API 层对 listByAccount 和 listResults 加 ?? [] 兜底。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
/**
|
|
* Admin Scheduled Tests API endpoints
|
|
* Handles scheduled test plan management for account connectivity monitoring
|
|
*/
|
|
|
|
import { apiClient } from '../client'
|
|
import type {
|
|
ScheduledTestPlan,
|
|
ScheduledTestResult,
|
|
CreateScheduledTestPlanRequest,
|
|
UpdateScheduledTestPlanRequest
|
|
} from '@/types'
|
|
|
|
/**
|
|
* List all scheduled test plans for an account
|
|
* @param accountId - Account ID
|
|
* @returns List of scheduled test plans
|
|
*/
|
|
export async function listByAccount(accountId: number): Promise<ScheduledTestPlan[]> {
|
|
const { data } = await apiClient.get<ScheduledTestPlan[]>(
|
|
`/admin/accounts/${accountId}/scheduled-test-plans`
|
|
)
|
|
return data ?? []
|
|
}
|
|
|
|
/**
|
|
* Create a new scheduled test plan
|
|
* @param req - Plan creation request
|
|
* @returns Created plan
|
|
*/
|
|
export async function create(req: CreateScheduledTestPlanRequest): Promise<ScheduledTestPlan> {
|
|
const { data } = await apiClient.post<ScheduledTestPlan>(
|
|
'/admin/scheduled-test-plans',
|
|
req
|
|
)
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Update an existing scheduled test plan
|
|
* @param id - Plan ID
|
|
* @param req - Fields to update
|
|
* @returns Updated plan
|
|
*/
|
|
export async function update(id: number, req: UpdateScheduledTestPlanRequest): Promise<ScheduledTestPlan> {
|
|
const { data } = await apiClient.put<ScheduledTestPlan>(
|
|
`/admin/scheduled-test-plans/${id}`,
|
|
req
|
|
)
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Delete a scheduled test plan
|
|
* @param id - Plan ID
|
|
*/
|
|
export async function deletePlan(id: number): Promise<void> {
|
|
await apiClient.delete(`/admin/scheduled-test-plans/${id}`)
|
|
}
|
|
|
|
/**
|
|
* List test results for a plan
|
|
* @param planId - Plan ID
|
|
* @param limit - Optional max number of results to return
|
|
* @returns List of test results
|
|
*/
|
|
export async function listResults(planId: number, limit?: number): Promise<ScheduledTestResult[]> {
|
|
const { data } = await apiClient.get<ScheduledTestResult[]>(
|
|
`/admin/scheduled-test-plans/${planId}/results`,
|
|
{
|
|
params: limit ? { limit } : undefined
|
|
}
|
|
)
|
|
return data ?? []
|
|
}
|
|
|
|
export const scheduledTestsAPI = {
|
|
listByAccount,
|
|
create,
|
|
update,
|
|
delete: deletePlan,
|
|
listResults
|
|
}
|
|
|
|
export default scheduledTestsAPI
|