feat(mock): implementierte Mock-Daten für 6 Webservice-Endpunkte + Umschaltung via .env
- Hinzugefügt: __mocks__/webservice/ - gisLinesStatus.js - gisStationsMeasurements.js - gisStationsStaticDistrict.js - gisStationsStatusDistrict.js - gisSystemStatic.js - userRights.js - In allen fetch*Service-Dateien Umschaltung implementiert (über NEXT_PUBLIC_USE_MOCKS) - Fallback auf Mock-Daten bei Entwicklung oder Offline-Modus - Unterstützt schnelles UI-Testing und isolierte Feature-Entwicklung ohne Backend
This commit is contained in:
@@ -1,28 +1,44 @@
|
||||
// /services/webservice/fetchUserRightsService.js
|
||||
|
||||
/**
|
||||
* Holt Benutzerrechte aus TALAS-Webservice oder aus Mocks.
|
||||
*
|
||||
* @returns {Promise<Array>} Rechte-Array
|
||||
* @throws {Error} bei Lade- oder Strukturfehler
|
||||
*/
|
||||
export const fetchUserRightsService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchUserRightsService");
|
||||
const { mockUserRights } = await import("../../__mocks__/webservice/userRights.js");
|
||||
return mockUserRights.Rights || [];
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("🔍 Rechte-Fetch URL:", url);
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
});
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("🔍 Rechte-Fetch URL:", url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der Benutzerrechte");
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der Benutzerrechte");
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
console.log("👤 Rechte-Response JSON:", json);
|
||||
|
||||
return json.Rights || [];
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
console.log("👤 Rechte-Response JSON:", json);
|
||||
return json.Rights || [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user