Refactor environment configuration for local development; update SMTP settings and add JWT secret, encryption key, and debug options. Enhance Nuxt configuration for development server and runtime settings. Introduce new membership application form with validation and PDF generation functionality. Update footer and navigation components to include new membership links. Revise user and session data in JSON files.
This commit is contained in:
90
server/api/membership/update-status.put.js
Normal file
90
server/api/membership/update-status.put.js
Normal file
@@ -0,0 +1,90 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { decryptObject, encryptObject } from '../../utils/encryption.js'
|
||||
import { saveMember } from '../../utils/members.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const { id, status, notes } = await readBody(event)
|
||||
|
||||
if (!id || !status) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'ID und Status sind erforderlich'
|
||||
})
|
||||
}
|
||||
|
||||
if (!['pending', 'approved', 'rejected'].includes(status)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Ungültiger Status'
|
||||
})
|
||||
}
|
||||
|
||||
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')
|
||||
const filePath = path.join(dataDir, `${id}.json`)
|
||||
|
||||
// Antrag laden
|
||||
const fileContent = await fs.readFile(filePath, 'utf8')
|
||||
const applicationData = JSON.parse(fileContent)
|
||||
|
||||
// Status aktualisieren
|
||||
applicationData.status = status
|
||||
applicationData.updatedAt = new Date().toISOString()
|
||||
|
||||
if (notes) {
|
||||
applicationData.notes = notes
|
||||
}
|
||||
|
||||
// Wenn genehmigt: In Mitgliederliste einfügen
|
||||
if (status === 'approved') {
|
||||
try {
|
||||
const decryptedData = decryptObject(applicationData.encryptedData, encryptionKey)
|
||||
|
||||
const newMember = {
|
||||
firstName: decryptedData.vorname,
|
||||
lastName: decryptedData.nachname,
|
||||
email: decryptedData.email,
|
||||
phone: decryptedData.telefon_privat || decryptedData.telefon_mobil || '',
|
||||
address: `${decryptedData.strasse}, ${decryptedData.plz} ${decryptedData.ort}`,
|
||||
notes: `Mitgliedschaftsart: ${applicationData.metadata.mitgliedschaftsart} | Genehmigt: ${new Date().toLocaleDateString('de-DE')}`,
|
||||
source: 'membership_application',
|
||||
applicationId: id
|
||||
}
|
||||
|
||||
await saveMember(newMember)
|
||||
applicationData.memberId = newMember.id
|
||||
|
||||
console.log(`Mitgliedschaftsantrag ${id} wurde genehmigt und in Mitgliederliste eingefügt`)
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Einfügen in Mitgliederliste:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Speichern
|
||||
await fs.writeFile(filePath, JSON.stringify(applicationData, null, 2), 'utf8')
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: status === 'approved' ? 'Antrag genehmigt und in Mitgliederliste eingefügt' : 'Status erfolgreich aktualisiert'
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Aktualisieren des Status:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Fehler beim Aktualisieren des Status'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user