refactor: POI aktualisieren auf updatePoiThunk + ID aus react-select umgestellt

- Thunk getDeviceIdByNameThunk entfernt
- idLD direkt aus Dropdown gelesen
- updatePoiThunk + updatePoiService vollständig eingebunden
- Fehlerbehandlung in handleSubmit verbessert
- Version erhöht auf 1.1.162
This commit is contained in:
Ismail Ali
2025-05-24 09:18:34 +02:00
parent b69a3efae3
commit fc6a706769
7 changed files with 98 additions and 24 deletions

View File

@@ -4,6 +4,31 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
--- ---
## [1.1.162] 2025-05-23
### ♻️ Refactor
- `PoiUpdateModal.js` vollständig auf direkte Geräte-ID (`idLD`) über `react-select` umgestellt
- Thunk `getDeviceIdByNameThunk` entfernt, da ID direkt im Dropdown verfügbar ist
- `updatePoiThunk` + `updatePoiService.js` erfolgreich integriert für POST-Anfrage
- `handleSubmit()` aktualisiert, robust gegen fehlende Felder
### 🧠 Architektur
- Geräteselektion nutzt nun die eindeutige ID (`idLD`) aus der Auswahl stabiler und performanter
- Alle POI-Änderungen laufen nun über Service + Thunk + Dispatch, ohne fetch()
### 🛠 Sicherheit & Wartbarkeit
- keine API-Abhängigkeit mehr für Gerätesuche
- einheitliche Redux-Thunk-Strategie eingehalten
### 🔧 Version
- 📦 Version erhöht auf **1.1.162**
---
## [1.1.161] 2025-05-23 ## [1.1.161] 2025-05-23
### ♻️ Refactor ### ♻️ Refactor

View File

@@ -7,6 +7,8 @@ import { selectMapLayersState } from "../../redux/slices/mapLayersSlice";
import { fetchPoiTypThunk } from "../../redux/thunks/database/fetchPoiTypThunk"; import { fetchPoiTypThunk } from "../../redux/thunks/database/fetchPoiTypThunk";
import { selectPoiTypData, selectPoiTypStatus } from "../../redux/slices/database/poiTypSlice"; import { selectPoiTypData, selectPoiTypStatus } from "../../redux/slices/database/poiTypSlice";
import { deletePoiThunk } from "../../redux/thunks/database/deletePoiThunk"; import { deletePoiThunk } from "../../redux/thunks/database/deletePoiThunk";
import { getDeviceIdByNameThunk } from "../../redux/thunks/database/getDeviceIdByNameThunk";
import { updatePoiThunk } from "../../redux/thunks/database/updatePoiThunk";
const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@@ -85,32 +87,22 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
const idLDResponse = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName?.value)}`);
const idLDData = await idLDResponse.json();
const idLD = idLDData.idLD;
try { try {
const response = await fetch("/api/talas_v5_DB/pois/updatePoi", { const idLD = deviceName?.value;
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
idPoi: poiId,
name: name,
description: description,
idPoiTyp: poiTypeId?.value, // Den ausgewählten Typ mitsenden
idLD: idLD,
}),
});
if (response.ok) { await dispatch(
onClose(); updatePoiThunk({
window.location.reload(); idPoi: poiId,
} else { name,
const errorResponse = await response.json(); description,
throw new Error(errorResponse.error || "Fehler beim Aktualisieren des POI."); idPoiTyp: poiTypeId?.value ?? poiData?.idPoiTyp,
} idLD: deviceName?.value, // ← direkt die ID aus react-select
})
).unwrap();
onClose();
window.location.reload(); // oder: dispatch(incrementTrigger());
} catch (error) { } catch (error) {
console.error("Fehler beim Aktualisieren des POI:", error); console.error("Fehler beim Aktualisieren des POI:", error);
alert("Fehler beim Aktualisieren des POI."); alert("Fehler beim Aktualisieren des POI.");
@@ -165,6 +157,13 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
minWidth: "300px", // Ensure the dropdown menu stays at the minimum width minWidth: "300px", // Ensure the dropdown menu stays at the minimum width
}), }),
}; };
console.log("→ Sende POI-Daten:", {
idPoi: poiId,
name,
description,
idPoiTyp: poiTypeId?.value,
idLD,
});
return ( return (
<div className="fixed inset-0 bg-black bg-opacity-10 flex justify-center items-center z-[1000]" onClick={onClose}> <div className="fixed inset-0 bg-black bg-opacity-10 flex justify-center items-center z-[1000]" onClick={onClose}>

View File

@@ -1,2 +1,2 @@
// /config/appVersion // /config/appVersion
export const APP_VERSION = "1.1.162"; export const APP_VERSION = "1.1.163";

View File

@@ -0,0 +1,12 @@
// /redux/thunks/database/getDeviceIdByNameThunk.js
import { createAsyncThunk } from "@reduxjs/toolkit";
import { getDeviceIdByNameService } from "../../../services/database/getDeviceIdByNameService";
export const getDeviceIdByNameThunk = createAsyncThunk("devices/getIdByName", async (deviceName, thunkAPI) => {
try {
return await getDeviceIdByNameService(deviceName);
} catch (error) {
return thunkAPI.rejectWithValue(error.message);
}
});

View File

@@ -0,0 +1,12 @@
// /redux/thunks/database/updatePoiThunk.js
import { createAsyncThunk } from "@reduxjs/toolkit";
import { updatePoiService } from "../../../services/database/updatePoiService";
export const updatePoiThunk = createAsyncThunk("pois/update", async (poi, thunkAPI) => {
try {
await updatePoiService(poi);
} catch (error) {
return thunkAPI.rejectWithValue(error.message);
}
});

View File

@@ -0,0 +1,10 @@
// /services/database/getDeviceIdByNameService.js
export const getDeviceIdByNameService = async (deviceName) => {
const response = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`);
if (!response.ok) {
throw new Error("Fehler beim Abrufen der Geräte-ID.");
}
const data = await response.json();
return data.idLD;
};

View File

@@ -0,0 +1,16 @@
// /services/database/updatePoiService.js
export const updatePoiService = async (poi) => {
const response = await fetch("/api/talas_v5_DB/pois/updatePoi", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(poi),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || "Fehler beim Aktualisieren des POI.");
}
};