added backup and email client

This commit is contained in:
2026-02-01 00:02:35 +01:00
parent ff857be01a
commit e4fdfbc95f
210 changed files with 24211 additions and 742 deletions
+32 -1
View File
@@ -27,8 +27,14 @@ async function getAllContracts(filters) {
}
if (type)
where.type = type;
if (status)
// Status-Filter: Deaktivierte Verträge standardmäßig ausblenden
if (status) {
where.status = status;
}
else {
// Wenn kein Status-Filter gesetzt, alle außer DEACTIVATED anzeigen
where.status = { not: client_1.ContractStatus.DEACTIVATED };
}
if (search) {
where.OR = [
// Basis-Vertragsfelder
@@ -125,6 +131,9 @@ async function getContractById(id, decryptPassword = false) {
tvDetails: true,
carInsuranceDetails: true,
stressfreiEmail: true,
followUpContract: {
select: { id: true, contractNumber: true, status: true },
},
},
});
if (!contract)
@@ -412,6 +421,19 @@ async function updateContract(id, data) {
return getContractById(id);
}
async function deleteContract(id) {
// Vertragskette erhalten beim Löschen:
// Wenn A → B → C und B gelöscht wird, soll C direkt auf A zeigen (A → C)
// 1. Zu löschenden Vertrag holen um dessen Vorgänger zu kennen
const contractToDelete = await prisma.contract.findUnique({
where: { id },
select: { previousContractId: true },
});
// 2. Folgevertrag(e) mit dem Vorgänger des gelöschten Vertrags verbinden
// So bleibt die Kette erhalten: A → B → C wird zu A → C
await prisma.contract.updateMany({
where: { previousContractId: id },
data: { previousContractId: contractToDelete?.previousContractId ?? null },
});
return prisma.contract.delete({ where: { id } });
}
async function createFollowUpContract(previousContractId) {
@@ -419,6 +441,14 @@ async function createFollowUpContract(previousContractId) {
if (!previousContract) {
throw new Error('Vorgängervertrag nicht gefunden');
}
// Prüfen ob bereits ein Folgevertrag existiert
const existingFollowUp = await prisma.contract.findFirst({
where: { previousContractId },
select: { id: true, contractNumber: true },
});
if (existingFollowUp) {
throw new Error(`Es existiert bereits ein Folgevertrag: ${existingFollowUp.contractNumber}`);
}
// Copy data but exclude provider credentials and some fields
const newContractData = {
customerId: previousContract.customerId,
@@ -441,6 +471,7 @@ async function createFollowUpContract(previousContractId) {
annualConsumption: previousContract.energyDetails.annualConsumption ?? undefined,
basePrice: previousContract.energyDetails.basePrice ?? undefined,
unitPrice: previousContract.energyDetails.unitPrice ?? undefined,
bonus: previousContract.energyDetails.bonus ?? undefined,
previousProviderName: previousContract.providerName ?? undefined,
previousCustomerNumber: previousContract.customerNumberAtProvider ?? undefined,
};