"feat: Refactor database connection in myp.db and update notifications"

This commit is contained in:
Till Tomczak 2025-05-29 14:50:32 +02:00
parent e1457ab02e
commit 7279da98d9
3 changed files with 34 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -14,9 +14,37 @@ class NotificationManager {
this.isOpen = false;
this.notifications = [];
// CSRF-Token aus Meta-Tag holen
this.csrfToken = this.getCSRFToken();
this.init();
}
/**
* Holt das CSRF-Token aus dem Meta-Tag
* @returns {string} Das CSRF-Token
*/
getCSRFToken() {
const metaTag = document.querySelector('meta[name="csrf-token"]');
return metaTag ? metaTag.getAttribute('content') : '';
}
/**
* Erstellt die Standard-Headers für API-Anfragen mit CSRF-Token
* @returns {Object} Headers-Objekt
*/
getAPIHeaders() {
const headers = {
'Content-Type': 'application/json',
};
if (this.csrfToken) {
headers['X-CSRFToken'] = this.csrfToken;
}
return headers;
}
init() {
if (!this.notificationToggle) return;
@ -241,9 +269,7 @@ class NotificationManager {
try {
const response = await fetch(`/api/notifications/${notificationId}/read`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
headers: this.getAPIHeaders()
});
if (response.ok) {
@ -253,6 +279,8 @@ class NotificationManager {
notification.read = true;
this.updateUI();
}
} else {
console.error('Fehler beim Markieren als gelesen:', response.status, response.statusText);
}
} catch (error) {
console.error('Fehler beim Markieren als gelesen:', error);
@ -263,9 +291,7 @@ class NotificationManager {
try {
const response = await fetch('/api/notifications/mark-all-read', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
headers: this.getAPIHeaders()
});
if (response.ok) {
@ -274,6 +300,8 @@ class NotificationManager {
notification.read = true;
});
this.updateUI();
} else {
console.error('Fehler beim Markieren aller als gelesen:', response.status, response.statusText);
}
} catch (error) {
console.error('Fehler beim Markieren aller als gelesen:', error);