📝 "Refactor session handling

This commit is contained in:
2025-06-13 07:32:57 +02:00
parent 691a4f2d41
commit eaf415c80f
86 changed files with 603 additions and 720 deletions

View File

@@ -405,25 +405,31 @@ function getPriorityBadge(level) {
* CRUD-Operationen
*/
async function approveRequest(requestId) {
if (!confirm('Möchten Sie diesen Gastauftrag wirklich genehmigen?')) return;
const notes = prompt('Genehmigungsnotizen (optional):');
if (notes === null) return; // User clicked cancel
try {
showLoading(true);
const url = `${API_BASE_URL}/api/guest-requests/${requestId}/approve`;
const url = `${API_BASE_URL}/api/requests/${requestId}/approve`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({}) // Leeres JSON-Objekt senden
body: JSON.stringify({
notes: notes || ''
})
});
const data = await response.json();
if (data.success) {
showNotification('✅ Gastauftrag erfolgreich genehmigt', 'success');
if (data.otp) {
showNotification(`🔑 OTP-Code für Gast: ${data.otp}`, 'info');
}
loadGuestRequests();
} else {
throw new Error(data.message || 'Fehler beim Genehmigen');
@@ -437,20 +443,23 @@ async function approveRequest(requestId) {
}
async function rejectRequest(requestId) {
const reason = prompt('Grund für die Ablehnung:');
if (!reason) return;
const reason = prompt('Grund für die Ablehnung (erforderlich):');
if (!reason || reason.trim() === '') {
showNotification('⚠️ Ablehnungsgrund ist erforderlich', 'warning');
return;
}
try {
showLoading(true);
const url = `${API_BASE_URL}/api/guest-requests/${requestId}/reject`;
const url = `${API_BASE_URL}/api/requests/${requestId}/deny`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({ reason })
body: JSON.stringify({ reason: reason.trim() })
});
const data = await response.json();
@@ -475,7 +484,7 @@ async function deleteRequest(requestId) {
try {
showLoading(true);
const url = `${API_BASE_URL}/api/guest-requests/${requestId}`;
const url = `${API_BASE_URL}/api/admin/requests/${requestId}`;
const response = await fetch(url, {
method: 'DELETE',
headers: {
@@ -615,15 +624,28 @@ async function performBulkAction(action) {
closeBulkModal();
const promises = selectedIds.map(async (id) => {
const url = `${API_BASE_URL}/api/guest-requests/${id}/${action}`;
const method = action === 'delete' ? 'DELETE' : 'POST';
let url, method, body = null;
if (action === 'approve') {
url = `${API_BASE_URL}/api/requests/${id}/approve`;
method = 'POST';
body = JSON.stringify({ notes: '' });
} else if (action === 'reject') {
url = `${API_BASE_URL}/api/requests/${id}/deny`;
method = 'POST';
body = JSON.stringify({ reason: 'Bulk-Ablehnung durch Administrator' });
} else if (action === 'delete') {
url = `${API_BASE_URL}/api/admin/requests/${id}`;
method = 'DELETE';
}
return fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
}
},
body: body
});
});