98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import { BaseService } from '../BaseService'
|
|
import type { BaseResponse, PaginationResponse } from '@/types/api/common'
|
|
import type {
|
|
GatewayOptions,
|
|
StopResumeRecord,
|
|
StopResumeQuery,
|
|
CardStopResumeQuery,
|
|
GatewayRule,
|
|
GatewayRuleQuery,
|
|
GatewayRuleInput,
|
|
GatewayRuleTestInput,
|
|
GatewayRuleTestResult,
|
|
GatewayGroup,
|
|
GatewayGroupQuery,
|
|
GatewayGroupInput,
|
|
GatewayCarrierStats,
|
|
GatewayCarrierTrend
|
|
} from '@/types/api/gateway'
|
|
|
|
const rulesUrl = '/api/admin/gateway-error-classifications'
|
|
const groupsUrl = '/api/admin/polling-rate-limit-groups'
|
|
|
|
export class GatewayService extends BaseService {
|
|
static getRecords(params: StopResumeQuery): Promise<PaginationResponse<StopResumeRecord>> {
|
|
return this.get('/api/admin/card-stop-resume-records', params)
|
|
}
|
|
|
|
static getCardRecords(
|
|
id: number,
|
|
params?: CardStopResumeQuery
|
|
): Promise<PaginationResponse<StopResumeRecord>> {
|
|
return this.get(`/api/admin/iot-cards/${id}/stop-resume-records`, params)
|
|
}
|
|
|
|
static getRules(params?: GatewayRuleQuery): Promise<PaginationResponse<GatewayRule>> {
|
|
return this.get(rulesUrl, params)
|
|
}
|
|
|
|
static createRule(data: GatewayRuleInput): Promise<BaseResponse<GatewayRule>> {
|
|
return this.post(rulesUrl, data)
|
|
}
|
|
|
|
static updateRule(id: number, data: GatewayRuleInput): Promise<BaseResponse<GatewayRule>> {
|
|
return this.put(`${rulesUrl}/${id}`, data)
|
|
}
|
|
|
|
static setRuleStatus(id: number, status: number): Promise<BaseResponse<unknown>> {
|
|
return this.put(`${rulesUrl}/${id}/status`, { status })
|
|
}
|
|
|
|
static deleteRule(id: number): Promise<BaseResponse<unknown>> {
|
|
return this.delete(`${rulesUrl}/${id}`)
|
|
}
|
|
|
|
static testRule(data: GatewayRuleTestInput): Promise<BaseResponse<GatewayRuleTestResult>> {
|
|
return this.post(`${rulesUrl}/test`, data)
|
|
}
|
|
|
|
static getOptions(): Promise<BaseResponse<GatewayOptions>> {
|
|
return this.get('/api/admin/polling-options')
|
|
}
|
|
|
|
static getGroups(params?: GatewayGroupQuery): Promise<PaginationResponse<GatewayGroup>> {
|
|
return this.get(groupsUrl, params)
|
|
}
|
|
|
|
static createGroup(data: GatewayGroupInput): Promise<BaseResponse<GatewayGroup>> {
|
|
return this.post(groupsUrl, data)
|
|
}
|
|
|
|
static getGroup(id: number): Promise<BaseResponse<GatewayGroup>> {
|
|
return this.get(`${groupsUrl}/${id}`)
|
|
}
|
|
|
|
static updateGroup(id: number, data: GatewayGroupInput): Promise<BaseResponse<GatewayGroup>> {
|
|
return this.put(`${groupsUrl}/${id}`, data)
|
|
}
|
|
|
|
static setGroupStatus(id: number, status: number): Promise<BaseResponse<unknown>> {
|
|
return this.put(`${groupsUrl}/${id}/status`, { status })
|
|
}
|
|
|
|
static deleteGroup(id: number): Promise<BaseResponse<unknown>> {
|
|
return this.delete(`${groupsUrl}/${id}`)
|
|
}
|
|
|
|
static getCarrierStats(minutes = 15): Promise<BaseResponse<GatewayCarrierStats>> {
|
|
return this.get('/api/admin/polling-stats/carriers', { minutes })
|
|
}
|
|
|
|
static getCarrierTrend(
|
|
carrierId: number,
|
|
params: { minutes?: number; bucket_minutes?: number } = {}
|
|
): Promise<BaseResponse<GatewayCarrierTrend>> {
|
|
return this.get(`/api/admin/polling-stats/carriers/${carrierId}/trend`, params)
|
|
}
|
|
}
|