40 lines
1.0 KiB
TypeScript
Raw Normal View History

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