-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoints.ts
More file actions
44 lines (35 loc) · 1.55 KB
/
Copy pathendpoints.ts
File metadata and controls
44 lines (35 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Waypoint } from "../types/Waypoint";
import api from "./api";
import { AxiosResponse } from "axios";
import { deserializeWaypoints, serializeWaypointForGCOM } from "./formatters";
export const armDrone = async (arm: boolean) => {
return await api.post("/drone/arm", { arm });
};
export const takeoffDrone = async (altitude?: number) => {
return await api.post("/drone/takeoff", { altitude });
};
export const getGCOM = async (): Promise<Waypoint[]> => {
return (await api.get("/drone/queue")) as Waypoint[];
};
export const getRoute = async (): Promise<Waypoint[]> => {
return (await api.get("/route")) as Waypoint[];
};
export const getWaypointsQuery = async (): Promise<Waypoint[]> => {
const response = await api.get("/waypoint");
const waypoints = deserializeWaypoints(response.data);
return waypoints;
};
export const createWaypointQuery = async (waypoint: Waypoint): Promise<AxiosResponse> => {
const serializedWaypoint = serializeWaypointForGCOM(waypoint);
return api.post("/waypoint/", serializedWaypoint);
};
export const updateWaypointQuery = async (waypoint: Waypoint): Promise<AxiosResponse> => {
const serializedWaypoint = serializeWaypointForGCOM(waypoint);
return api.patch(`/waypoint/${waypoint.id}/`, serializedWaypoint);
};
export const deleteWaypointQuery = async (id: string): Promise<AxiosResponse> => {
return api.delete(`/waypoint/${id}/`);
};
export const reorderWaypointsQuery = async (waypointIds: string[]): Promise<AxiosResponse> => {
return api.post("/waypoint/reorder", waypointIds);
};