73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
import fs from 'fs/promises'
|
|
import path from 'path'
|
|
import { decryptObject } from '../../utils/encryption.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const config = useRuntimeConfig()
|
|
const encryptionKey = config.encryptionKey
|
|
|
|
if (!encryptionKey) {
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: 'Verschlüsselungsschlüssel nicht konfiguriert'
|
|
})
|
|
}
|
|
|
|
const dataDir = path.join(process.cwd(), 'server/data/membership-applications')
|
|
|
|
// Prüfen ob Verzeichnis existiert
|
|
try {
|
|
await fs.access(dataDir)
|
|
} catch {
|
|
return []
|
|
}
|
|
|
|
// Alle Anträge laden
|
|
const files = await fs.readdir(dataDir)
|
|
const applications = []
|
|
|
|
for (const file of files) {
|
|
if (file.endsWith('.json')) {
|
|
try {
|
|
const filePath = path.join(dataDir, file)
|
|
const fileContent = await fs.readFile(filePath, 'utf8')
|
|
const applicationData = JSON.parse(fileContent)
|
|
|
|
// Verschlüsselte Daten entschlüsseln
|
|
const decryptedData = decryptObject(applicationData.encryptedData, encryptionKey)
|
|
|
|
applications.push({
|
|
id: applicationData.id,
|
|
timestamp: applicationData.timestamp,
|
|
status: applicationData.status,
|
|
metadata: applicationData.metadata,
|
|
// Entschlüsselte persönliche Daten
|
|
personalData: {
|
|
nachname: decryptedData.nachname,
|
|
vorname: decryptedData.vorname,
|
|
email: decryptedData.email,
|
|
telefon_privat: decryptedData.telefon_privat,
|
|
telefon_mobil: decryptedData.telefon_mobil
|
|
}
|
|
})
|
|
} catch (error) {
|
|
console.error(`Fehler beim Laden von ${file}:`, error)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Nach Zeitstempel sortieren (neueste zuerst)
|
|
applications.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp))
|
|
|
|
return applications
|
|
|
|
} catch (error) {
|
|
console.error('Fehler beim Laden der Mitgliedschaftsanträge:', error)
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: 'Fehler beim Laden der Anträge'
|
|
})
|
|
}
|
|
})
|