52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { ConnectedAircraft, PositionLog, Prisma, PublicUser, Station } from "@repo/db";
|
|
import axios from "axios";
|
|
import { serverApi } from "_helpers/axios";
|
|
import { checkSimulatorConnected } from "_helpers/simulatorConnected";
|
|
|
|
export const getConnectedAircraftsAPI = async () => {
|
|
const res = await axios.get<(ConnectedAircraft & { Station: Station })[]>("/api/aircrafts"); // return only connected aircrafts
|
|
if (res.status !== 200) {
|
|
throw new Error("Failed to fetch stations");
|
|
}
|
|
return res.data.filter((a) => checkSimulatorConnected(a));
|
|
};
|
|
|
|
export const editConnectedAircraftAPI = async (
|
|
id: number,
|
|
mission: Prisma.ConnectedAircraftUpdateInput,
|
|
) => {
|
|
const respone = await serverApi.patch<ConnectedAircraft>(`/aircrafts/${id}`, mission);
|
|
return respone.data;
|
|
};
|
|
|
|
export const getConnectedAircraftPositionLogAPI = async ({ id }: { id: number }) => {
|
|
const res = await axios.get<PositionLog[]>("/api/aircrafts/positionlog", {
|
|
params: { connectedAircraftId: id },
|
|
});
|
|
if (res.status !== 200) {
|
|
throw new Error("Failed to fetch aircraft position log");
|
|
}
|
|
return res.data;
|
|
};
|
|
|
|
export const kickAircraftAPI = async ({
|
|
id,
|
|
bann,
|
|
reason,
|
|
until = null,
|
|
}: {
|
|
id: number;
|
|
bann?: boolean;
|
|
reason: string;
|
|
until?: Date | null;
|
|
}) => {
|
|
const res = await serverApi.delete(`/aircrafts/${id}`, {
|
|
data: { bann, reason, until },
|
|
});
|
|
console.log(res.status);
|
|
if (res.status != 204) {
|
|
throw new Error("Failed to kick aircraft");
|
|
}
|
|
return res.data;
|
|
};
|