129 lines
4.1 KiB
JavaScript
129 lines
4.1 KiB
JavaScript
// services/apiService.js
|
|
|
|
export const fetchGisStatusStations = async (idMap, idUser) => {
|
|
try {
|
|
const response = await fetch(
|
|
`/api/talas5/webserviceMap/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`
|
|
);
|
|
if (!response.ok) {
|
|
throw new Error(`Error: ${response.statusText}`);
|
|
}
|
|
const data = await response.json();
|
|
console.log("GisStatusStations:", data);
|
|
return data;
|
|
} catch (error) {
|
|
console.error("Fehler beim Abrufen der Daten:", error);
|
|
throw error; // Fehler weiter werfen, um ihn in der Komponente behandeln zu können
|
|
}
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
export const fetchPriorityConfig = async () => {
|
|
try {
|
|
const response = await fetch("/api/talas_v5_DB/priorityConfig");
|
|
const data = await response.json();
|
|
console.log("Prioritätskonfiguration:", data);
|
|
setPriorityConfig(data);
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der Prioritätskonfiguration:", error);
|
|
}
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
export const fetchPoiData = async (idPoi) => {
|
|
const response = await fetch(
|
|
`/api/talas_v5_DB/pois/getPoiById?idPoi=${idPoi}`
|
|
);
|
|
if (!response.ok) {
|
|
console.error("Fehler beim Abrufen der POI-Daten");
|
|
return;
|
|
}
|
|
const data = await response.json();
|
|
setCurrentPoiData({
|
|
idPoi,
|
|
name: data.name,
|
|
description: data.description,
|
|
});
|
|
//console.log("POI-Daten2:", currentPoiData);
|
|
setShowPoiUpdateModal(true);
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
// Funktion zum Aktualisieren der Position in der Datenbank
|
|
export const updateLocationInDatabase = async (
|
|
id,
|
|
newLatitude,
|
|
newLongitude
|
|
) => {
|
|
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
id,
|
|
latitude: newLatitude,
|
|
longitude: newLongitude,
|
|
}),
|
|
});
|
|
|
|
if (response.ok) {
|
|
//schreib die neue Kooridnaten in die Console
|
|
//akuellisiere die Position in der Datenbank mit den neuen Koordinaten mit updateLocation mit SQL Anweisung UPDATE
|
|
} else {
|
|
console.error("Fehler beim Aktualisieren der Position");
|
|
}
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
// Funktionen zur Überwachung der Internetverbindung
|
|
export const checkInternet = () => {
|
|
fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" })
|
|
.then((response) => setOnline(response.ok))
|
|
.catch(() => setOnline(false));
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
export const fetchUserRights = async (serverURL) => {
|
|
try {
|
|
const response = await fetch(
|
|
`${serverURL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${c}&idUser=${user}`
|
|
//`${serverURL}/api/talas5/webserviceMap/GisSystemStatic?idMap=${c}&idUser=${user}` //Berechtigung zum hinzufügen von POIs in der Karte
|
|
//`${serverURL}/api/rights?idMap=${c}&idUser=${user}`
|
|
);
|
|
const data = await response.json();
|
|
//console.log("Benutzerrechte:", data);
|
|
const rightsArray = data.Rights; // Nehmen an, dass 'Rights' das Array von Rechten ist
|
|
|
|
// Speichert die IDs der Rechte in einem Array
|
|
const userRightsIds = rightsArray.map((right) => right.IdRight);
|
|
setUserRights(userRightsIds); // Speichert die Rechte in den Zustand
|
|
|
|
//console.log("Benutzerrechte:", rightsArray);
|
|
//console.log("Benutzerrechte IDs:", userRightsIds);
|
|
//console.log("Benutzerrechte in if :", userRightsIds.includes(56));
|
|
setHasRights(userRightsIds.includes(56));
|
|
} catch (error) {
|
|
console.error("Fehler beim Abrufen der Benutzerrechte", error);
|
|
}
|
|
};
|
|
|
|
// ----------------------------------------------
|
|
export const fetchDeviceNameById = async (idLD) => {
|
|
try {
|
|
const response = await fetch(
|
|
`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`
|
|
);
|
|
const data = await response.json();
|
|
if (response.ok) {
|
|
return data.name;
|
|
} else {
|
|
throw new Error(data.error || "Gerät nicht gefunden");
|
|
}
|
|
} catch (error) {
|
|
console.error(
|
|
"Fehler beim Abrufen des Gerätenamens in MapComponent.js:",
|
|
error
|
|
);
|
|
return "Unbekannt";
|
|
}
|
|
};
|