Fixed docker deploments, moved files to _folders in dispatch app
This commit is contained in:
19
apps/dispatch/app/_querys/aircrafts.ts
Normal file
19
apps/dispatch/app/_querys/aircrafts.ts
Normal 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;
|
||||
};
|
||||
19
apps/dispatch/app/_querys/connected-user.ts
Normal file
19
apps/dispatch/app/_querys/connected-user.ts
Normal 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;
|
||||
};
|
||||
14
apps/dispatch/app/_querys/keywords.ts
Normal file
14
apps/dispatch/app/_querys/keywords.ts
Normal 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;
|
||||
};
|
||||
62
apps/dispatch/app/_querys/missions.ts
Normal file
62
apps/dispatch/app/_querys/missions.ts
Normal 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}`);
|
||||
};
|
||||
51
apps/dispatch/app/_querys/osm.ts
Normal file
51
apps/dispatch/app/_querys/osm.ts
Normal 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 || "",
|
||||
},
|
||||
};
|
||||
};
|
||||
13
apps/dispatch/app/_querys/report.ts
Normal file
13
apps/dispatch/app/_querys/report.ts
Normal 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;
|
||||
};
|
||||
14
apps/dispatch/app/_querys/stations.ts
Normal file
14
apps/dispatch/app/_querys/stations.ts
Normal 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;
|
||||
};
|
||||
12
apps/dispatch/app/_querys/user.ts
Normal file
12
apps/dispatch/app/_querys/user.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user