gdpr audit implemented, email log, vollmachten, pdf delete cancel data privacy and vollmachten, removed message no id card in engergy car, and other contracts that are not telecom contracts, added insert counter for engery
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as consentPublicService from '../services/consent-public.service.js';
|
||||
import { createAuditLog } from '../services/audit.service.js';
|
||||
import { CONSENT_TYPE_LABELS } from '../services/consent.service.js';
|
||||
import { ConsentType } from '@prisma/client';
|
||||
|
||||
/**
|
||||
* Öffentliche Consent-Seite: Kundendaten + Datenschutztext + Status
|
||||
*/
|
||||
export async function getConsentPage(req: Request, res: Response) {
|
||||
try {
|
||||
const { hash } = req.params;
|
||||
|
||||
const result = await consentPublicService.getCustomerByConsentHash(hash);
|
||||
if (!result) {
|
||||
return res.status(404).json({ success: false, error: 'Ungültiger Link' });
|
||||
}
|
||||
|
||||
const privacyPolicyHtml = await consentPublicService.getPrivacyPolicyHtml(result.customer.id);
|
||||
|
||||
// Consent-Status mit Labels
|
||||
const consentsWithLabels = result.consents.map((c) => ({
|
||||
consentType: c.consentType,
|
||||
status: c.status,
|
||||
label: CONSENT_TYPE_LABELS[c.consentType as ConsentType]?.label || c.consentType,
|
||||
description: CONSENT_TYPE_LABELS[c.consentType as ConsentType]?.description || '',
|
||||
grantedAt: c.grantedAt,
|
||||
}));
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: {
|
||||
customer: {
|
||||
firstName: result.customer.firstName,
|
||||
lastName: result.customer.lastName,
|
||||
customerNumber: result.customer.customerNumber,
|
||||
},
|
||||
privacyPolicyHtml,
|
||||
consents: consentsWithLabels,
|
||||
allGranted: consentsWithLabels.every((c) => c.status === 'GRANTED'),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Consent-Seite:', error);
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Laden' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle 4 Einwilligungen erteilen (öffentlicher Link)
|
||||
*/
|
||||
export async function grantAllConsents(req: Request, res: Response) {
|
||||
try {
|
||||
const { hash } = req.params;
|
||||
const ipAddress = req.ip || req.socket.remoteAddress || 'unknown';
|
||||
|
||||
const results = await consentPublicService.grantAllConsentsPublic(hash, ipAddress);
|
||||
|
||||
// Audit-Log (manuell, da keine Auth-Middleware)
|
||||
const customer = await consentPublicService.getCustomerByConsentHash(hash);
|
||||
if (customer) {
|
||||
for (const type of Object.values(ConsentType)) {
|
||||
await createAuditLog({
|
||||
userEmail: customer.customer.email || 'public-link',
|
||||
action: 'UPDATE',
|
||||
sensitivity: 'HIGH',
|
||||
resourceType: 'CustomerConsent',
|
||||
resourceId: `${customer.customer.id}:${type}`,
|
||||
resourceLabel: `Einwilligung ${type} erteilt via Public-Link`,
|
||||
endpoint: `/api/public/consent/${hash}/grant`,
|
||||
httpMethod: 'POST',
|
||||
ipAddress,
|
||||
dataSubjectId: customer.customer.id,
|
||||
legalBasis: 'DSGVO Art. 6 Abs. 1 lit. a',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ success: true, data: results });
|
||||
} catch (error: any) {
|
||||
console.error('Fehler beim Erteilen der Einwilligungen:', error);
|
||||
res.status(400).json({ success: false, error: error.message || 'Fehler beim Erteilen' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Datenschutzerklärung als PDF
|
||||
*/
|
||||
export async function getConsentPdf(req: Request, res: Response) {
|
||||
try {
|
||||
const { hash } = req.params;
|
||||
|
||||
const result = await consentPublicService.getCustomerByConsentHash(hash);
|
||||
if (!result) {
|
||||
return res.status(404).json({ success: false, error: 'Ungültiger Link' });
|
||||
}
|
||||
|
||||
const pdfBuffer = await consentPublicService.generateConsentPdf(result.customer.id);
|
||||
|
||||
res.setHeader('Content-Type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', 'inline; filename="datenschutzerklaerung.pdf"');
|
||||
res.send(pdfBuffer);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Generieren des PDFs:', error);
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Generieren' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user