2025-05-11 18:46:59 +08:00

64 lines
1.6 KiB
TypeScript

import http from '@core/http';
import type { RobotDetail, RobotGroup, RobotInfo } from './type';
const enum API {
= '/robot/getAll',
= '/robot/register',
= '/robot/seizeByIds',
= 'robot/syncByGroupId',
}
export async function getAllRobots(): Promise<Array<RobotInfo>> {
type D = RobotInfo[];
try {
const data = await http.post<D>(API.);
return data ?? [];
} catch (error) {
console.debug(error);
return [];
}
}
export async function registerRobot(robot: Omit<RobotDetail, 'id'>): Promise<RobotInfo | null> {
type B = Omit<RobotDetail, 'id'>;
type D = RobotInfo;
try {
const body = robot;
const data = await http.post<D, B>(API., body);
return data ?? null;
} catch (error) {
console.debug(error);
return null;
}
}
export async function seizeRobotByIds(ids: Array<RobotInfo['id']>): Promise<Array<RobotInfo['id']>> {
if (!ids.length) return [];
type B = { ids: string[] };
type D = string[];
try {
const body = { ids };
const data = await http.post<D, B>(API., body);
return data ?? [];
} catch (error) {
console.debug(error);
return [];
}
}
export async function syncGroupRobotsById(id: RobotGroup['id'], sid: RobotGroup['sid']): Promise<boolean> {
if (!id || !sid) return false;
type B = { id: string; sid: string };
type D = void;
try {
const body = { id, sid };
await http.post<D, B>(API., body);
return true;
} catch (error) {
console.debug(error);
return false;
}
}