Datenschutz vollmacht fixed, two time counter added
This commit is contained in:
@@ -146,13 +146,35 @@ export async function updateAuthorizationDocument(
|
||||
* Vollmacht-Dokument löschen
|
||||
*/
|
||||
export async function deleteAuthorizationDocument(customerId: number, representativeId: number) {
|
||||
// Prüfen ob die Vollmacht per Papier erteilt wurde
|
||||
const auth = await prisma.representativeAuthorization.findUnique({
|
||||
where: { customerId_representativeId: { customerId, representativeId } },
|
||||
select: { source: true, documentPath: true },
|
||||
});
|
||||
|
||||
if (!auth) throw new Error('Vollmacht nicht gefunden');
|
||||
|
||||
// Datei löschen
|
||||
if (auth.documentPath) {
|
||||
try {
|
||||
const filePath = path.join(process.cwd(), auth.documentPath);
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fehler beim Löschen der Vollmacht-PDF:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn per Papier erteilt → Vollmacht widerrufen
|
||||
// Wenn per Portal/Online erteilt → nur PDF entfernen, Vollmacht bleibt
|
||||
const withdrawData = auth.source === 'papier'
|
||||
? { documentPath: null, isGranted: false, withdrawnAt: new Date() }
|
||||
: { documentPath: null };
|
||||
|
||||
return prisma.representativeAuthorization.update({
|
||||
where: {
|
||||
customerId_representativeId: { customerId, representativeId },
|
||||
},
|
||||
data: {
|
||||
documentPath: null,
|
||||
},
|
||||
where: { customerId_representativeId: { customerId, representativeId } },
|
||||
data: withdrawData,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user