Fixed docker deploments, moved files to _folders in dispatch app

This commit is contained in:
PxlLoewe
2025-05-27 17:34:44 -07:00
parent 5d5b2dc91f
commit 571ddfba85
60 changed files with 251 additions and 406 deletions

View File

@@ -0,0 +1,19 @@
import { ConnectedAircraft, Prisma, Station } from "@repo/db";
import axios from "axios";
import { serverApi } from "_helpers/axios";
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;
};
export const editConnectedAircraftAPI = async (
id: number,
mission: Prisma.ConnectedAircraftUpdateInput,
) => {
const respone = await serverApi.patch<ConnectedAircraft>(`/aircrafts/${id}`, mission);
return respone.data;
};

View File

@@ -0,0 +1,19 @@
import { ConnectedAircraft, ConnectedDispatcher, Prisma } from "@repo/db";
import axios from "axios";
export const getConnectedUserAPI = async (
filter?: Prisma.KeywordWhereInput,
) => {
const res = await axios.get<(ConnectedAircraft | ConnectedDispatcher)[]>(
"/api/connected-user",
{
params: {
filter: JSON.stringify(filter),
},
},
);
if (res.status !== 200) {
throw new Error("Failed to fetch Connected User");
}
return res.data;
};

View File

@@ -0,0 +1,14 @@
import { Keyword, Prisma } from "@repo/db";
import axios from "axios";
export const getKeywordsAPI = async (filter?: Prisma.KeywordWhereInput) => {
const res = await axios.get<Keyword[]>("/api/keywords", {
params: {
filter: JSON.stringify(filter),
},
});
if (res.status !== 200) {
throw new Error("Failed to fetch keywords");
}
return res.data;
};

View File

@@ -0,0 +1,62 @@
import { Mission, MissionSdsLog, Prisma } from "@repo/db";
import axios from "axios";
import { serverApi } from "_helpers/axios";
export const getMissionsAPI = async (filter?: Prisma.MissionWhereInput) => {
const res = await axios.get<Mission[]>("/api/missions", {
params: {
filter: JSON.stringify(filter),
},
});
if (res.status !== 200) {
throw new Error("Failed to fetch stations");
}
return res.data;
};
export const createMissionAPI = async (mission: Prisma.MissionCreateInput) => {
const response = await serverApi.put<Mission>("/mission", mission);
return response.data;
};
export const editMissionAPI = async (id: number, mission: Prisma.MissionUpdateInput) => {
const respone = await serverApi.patch<Mission>(`/mission/${id}`, mission);
return respone.data;
};
export const sendSdsMessageAPI = async (id: number, sdsMessage: MissionSdsLog) => {
const respone = await serverApi.post<Mission>(`/mission/${id}/send-sds`, sdsMessage);
return respone.data;
};
export const startHpgValidation = async (
id: number,
config?: {
alertWhenValid?: boolean;
},
) => {
const respone = await serverApi.post<Mission>(`/mission/${id}/validate-hpg`, config);
return respone.data;
};
export const sendMissionAPI = async (
id: number,
{
stationId,
vehicleName,
}: {
stationId?: number;
vehicleName?: "ambulance" | "police" | "firebrigade";
},
) => {
const respone = await serverApi.post<{
message: string;
}>(`/mission/${id}/send-alert`, {
stationId,
vehicleName,
});
return respone.data;
};
export const deleteMissionAPI = async (id: number) => {
await serverApi.delete(`/mission/${id}`);
};

View File

@@ -0,0 +1,51 @@
import { raw } from "../../../../packages/database/generated/client/runtime/library";
export const getOsmAddress = async (lat: number, lng: number) => {
const address = await fetch(
`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json`,
);
const data = (await address.json()) as {
address?: {
ISO3166_2_lvl4?: string;
country?: string;
country_code?: string;
county?: string;
house_number?: string;
municipality?: string;
postcode?: string;
road?: string;
state?: string;
city?: string;
town?: string;
};
display_name?: string;
importance?: number;
lat?: string;
licence?: string;
lon?: string;
name?: string;
osm_id?: number;
osm_type?: string;
place_id?: number;
place_rank?: number;
type?: string;
};
let addressStreet = "";
if (!data.address?.road && !data.address?.house_number) {
addressStreet = "keine Straße, keine HN";
} else if (data.address?.road) {
addressStreet += data.address.road;
} else if (data.address?.house_number) {
addressStreet += data.address.house_number;
}
return {
raw: data,
parsed: {
addressCity: data.address?.city || data.address?.town || "",
addressStreet,
addressZip: data.address?.postcode || "",
},
};
};

View File

@@ -0,0 +1,13 @@
import { Prisma, Report } from "@repo/db";
import { serverApi } from "_helpers/axios";
export const sendReportAPI = async (
report:
| (Prisma.Without<Prisma.ReportCreateInput, Prisma.ReportUncheckedCreateInput> &
Prisma.ReportUncheckedCreateInput)
| (Prisma.Without<Prisma.ReportUncheckedCreateInput, Prisma.ReportCreateInput> &
Prisma.ReportCreateInput),
) => {
const repsonse = await serverApi.put("/report", report);
return repsonse.data as Report;
};

View File

@@ -0,0 +1,14 @@
import { Prisma, Station } from "@repo/db";
import axios from "axios";
export const getStationsAPI = async (filter?: Prisma.StationWhereInput) => {
const res = await axios.get<Station[]>("/api/stations", {
params: {
filter: JSON.stringify(filter),
},
});
if (res.status !== 200) {
throw new Error("Failed to fetch stations");
}
return res.data;
};

View File

@@ -0,0 +1,12 @@
import { Prisma, User } from "@repo/db";
import axios from "axios";
export const editUserAPI = async (id: string, user: Prisma.UserUpdateInput) => {
const response = await axios.post<User>(`/api/user?id=${id}`, user);
return response.data;
};
export const getUserAPI = async (id: string) => {
const response = await axios.get<User>(`/api/user?id=${id}`);
return response.data;
};