Compare commits
29 Commits
v1.1.0
...
083913cadb
| Author | SHA1 | Date | |
|---|---|---|---|
| 083913cadb | |||
| 4c0cc90734 | |||
| 70e97d3ece | |||
| 8dff0310a6 | |||
| ab971618d5 | |||
| 4407bbfbb8 | |||
| 365c7994d5 | |||
| 2c7a87ccd3 | |||
| 45f63d1c48 | |||
| 2d3ca28691 | |||
| 4201a90fd0 | |||
| 3fb1925a98 | |||
| 63ebf3e75f | |||
| 27a0fdbc45 | |||
| 6f293211a4 | |||
| 70e5190594 | |||
| 7d07d52774 | |||
| 75c1f9a7bb | |||
| 62010b05d5 | |||
| e401c11e40 | |||
| d206b360a6 | |||
| 096aa63c6f | |||
| 77602bb4ac | |||
| e763952a84 | |||
| 3823f8aa50 | |||
| 0671565433 | |||
| e145edaa90 | |||
| 3b4a680326 | |||
| 389b878dbd |
@@ -46,6 +46,15 @@ backups
|
|||||||
backend/uploads
|
backend/uploads
|
||||||
backend/backups
|
backend/backups
|
||||||
|
|
||||||
|
# Daten-Verzeichnis (Bind-Mounts zur Laufzeit, nicht im Build-Context)
|
||||||
|
data/
|
||||||
|
|
||||||
|
# Plesk-Test (nicht für Container)
|
||||||
|
plesktest/
|
||||||
|
|
||||||
|
# Backup-Klone des Repos
|
||||||
|
opencrm-backup-*/
|
||||||
|
|
||||||
# Prisma migrations (included, but not dev db)
|
# Prisma migrations (included, but not dev db)
|
||||||
*.db
|
*.db
|
||||||
*.db-journal
|
*.db-journal
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# OpenCRM – zentrale Konfiguration
|
||||||
|
# ==================================
|
||||||
|
# Kopiere diese Datei zu .env und passe die Werte an.
|
||||||
|
# Diese .env wird sowohl vom Backend (npm run dev) als auch von Docker
|
||||||
|
# Compose verwendet.
|
||||||
|
|
||||||
|
# ============== PORTS (extern erreichbar auf dem Host) ==============
|
||||||
|
OPENCRM_PORT=3010 # Backend + Frontend (alles unter einer URL)
|
||||||
|
ADMINER_PORT=8090 # Adminer (Datenbank-UI). 8081 ist häufig schon belegt.
|
||||||
|
DB_PORT=3306 # MariaDB extern (für lokale Tools/Dev). 0 = nicht freigeben.
|
||||||
|
|
||||||
|
# ============== DATEN-PFADE (Bind-Mounts) ==============
|
||||||
|
# Relativ zum Projektverzeichnis. Werden zur Laufzeit angelegt.
|
||||||
|
DATA_DIR=./data
|
||||||
|
DB_DATA_DIR=./data/db
|
||||||
|
UPLOADS_DIR=./data/uploads
|
||||||
|
FACTORY_DEFAULTS_DIR=./data/factory-defaults
|
||||||
|
BACKUPS_DIR=./data/backups
|
||||||
|
|
||||||
|
# ============== DATENBANK ==============
|
||||||
|
# Der App-User (DB_USER) wird beim ersten Start automatisch von MariaDB
|
||||||
|
# angelegt (über MARIADB_USER/MARIADB_PASSWORD im docker-compose) – mit
|
||||||
|
# GRANT ALL PRIVILEGES auf ${DB_NAME}.*. Damit nutzt das Backend NICHT root.
|
||||||
|
# DB_ROOT_PASSWORD ist nur für Adminer / Notfall-Wartung.
|
||||||
|
DB_HOST=localhost # Im Container überschreibt docker-compose das auf "db"
|
||||||
|
DB_NAME=opencrm
|
||||||
|
DB_USER=opencrm
|
||||||
|
DB_PASSWORD=change-this-password
|
||||||
|
DB_ROOT_PASSWORD=change-this-root-password
|
||||||
|
|
||||||
|
# Connection-String wird aus den DB_*-Komponenten zusammengebaut (dotenv-expand).
|
||||||
|
# Manuell überschreiben nur wenn Sonderfälle (z.B. extra Query-Parameter).
|
||||||
|
# Hinweis: für lokales Dev mit MariaDB im Container nutze DB_HOST=localhost,
|
||||||
|
# weil docker-compose den DB-Port auf 127.0.0.1:DB_PORT mappt.
|
||||||
|
DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||||
|
|
||||||
|
# ============== SECURITY ==============
|
||||||
|
# JWT-Secret: min. 32 Zeichen. Generieren: openssl rand -hex 64
|
||||||
|
JWT_SECRET=change-this-to-a-very-long-random-secret-please-rotate-before-production
|
||||||
|
JWT_EXPIRES_IN=7d
|
||||||
|
|
||||||
|
# Encryption-Key für Portal-Credentials: GENAU 64 Hex-Zeichen.
|
||||||
|
# Generieren: openssl rand -hex 32
|
||||||
|
ENCRYPTION_KEY=change-this-to-64-hex-characters-please-rotate-before-production-xx
|
||||||
|
|
||||||
|
# Server
|
||||||
|
NODE_ENV=development
|
||||||
|
PORT=3001 # Backend-internal Port (Dev: localhost:3001)
|
||||||
|
LISTEN_ADDR=0.0.0.0 # In Docker = 0.0.0.0, in Bare-Metal-Production = 127.0.0.1
|
||||||
|
|
||||||
|
# CORS – nur in Production setzen, wenn Frontend auf separater Domain läuft.
|
||||||
|
# Beispiel: CORS_ORIGINS=https://crm.deine-domain.de
|
||||||
|
# CORS_ORIGINS=
|
||||||
|
|
||||||
|
# HTTPS-only-Header (HSTS + upgrade-insecure-requests) – NUR aktivieren, wenn
|
||||||
|
# wirklich ein TLS-Proxy (Caddy/Traefik/Nginx) vor OpenCRM steht. Sonst sperrt
|
||||||
|
# sich der Browser bei direktem http://ip:port-Zugriff selbst aus
|
||||||
|
# (ERR_SSL_PROTOCOL_ERROR auf den Assets).
|
||||||
|
HTTPS_ENABLED=false
|
||||||
|
|
||||||
|
# ============== ADMINER (DB-UI) ==============
|
||||||
|
# Theme-Auswahl. Verfügbare Designs im offiziellen adminer:latest Image:
|
||||||
|
# adminer-dark, brade, bueltge, dracula, esterka, flat, galkaev,
|
||||||
|
# haeckel, hever, konya, lavender-light, lucas-sandery, mancave,
|
||||||
|
# mvt, nette, ng9, nicu, pappu687, paranoiq, pepa-linha, pokorny,
|
||||||
|
# price, rmsoft, rmsoft_blue, rmsoft_blue-dark, win98
|
||||||
|
# Empfehlung: dracula (dark) oder adminer-dark – beide modern.
|
||||||
|
ADMINER_DESIGN=dracula
|
||||||
|
|
||||||
|
# ============== SEED ==============
|
||||||
|
# Bei leerer DB seedet der Container automatisch (legt admin@admin.com / admin
|
||||||
|
# + Stammdaten an) – nichts zu konfigurieren.
|
||||||
|
# Nur wenn man eine NICHT-leere DB nochmal forciert seeden will (z.B. nach
|
||||||
|
# Reset / Stammdaten-Update), kurz auf 'true' setzen, neu starten, dann
|
||||||
|
# wieder zurück.
|
||||||
|
RUN_SEED=false
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
# Root-Gitignore: gemeinsame Patterns für Repo-Root + nested Verzeichnisse
|
||||||
|
# (backend/, frontend/, docker/ haben zusätzlich eigene .gitignore-Files)
|
||||||
|
|
||||||
|
# Environment – echte Secrets blocken, .env.example weiter mittracken
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Temp
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
|
||||||
|
# Docker-Bind-Mounts: Inhalt nicht tracken, Verzeichnisstruktur via .gitkeep behalten
|
||||||
|
data/db/*
|
||||||
|
!data/db/.gitkeep
|
||||||
|
data/uploads/*
|
||||||
|
!data/uploads/.gitkeep
|
||||||
|
data/factory-defaults/*
|
||||||
|
!data/factory-defaults/.gitkeep
|
||||||
|
data/backups/*
|
||||||
|
!data/backups/.gitkeep
|
||||||
|
|
||||||
|
# Factory-Defaults-Drop-Box (Export-ZIPs zwischen dev/prod hin und her)
|
||||||
|
factory-exports/*
|
||||||
|
!factory-exports/.gitkeep
|
||||||
@@ -47,32 +47,62 @@ Web-basiertes CRM-System für Kundenverwaltung mit Verträgen (Energie, Telekomm
|
|||||||
> - Express 4.x → `@types/express@^4.17.x`
|
> - Express 4.x → `@types/express@^4.17.x`
|
||||||
> - Express 5.x → `@types/express@^5.x` (erst bei offiziellem Release empfohlen)
|
> - Express 5.x → `@types/express@^5.x` (erst bei offiziellem Release empfohlen)
|
||||||
|
|
||||||
|
## Quick-Start mit Docker (empfohlen)
|
||||||
|
|
||||||
|
Komplettes Setup mit MariaDB + OpenCRM + Adminer (DB-UI) in 3 Befehlen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd opencrm
|
||||||
|
cp .env.example .env # Werte anpassen, Secrets rotieren!
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Browser:
|
||||||
|
- **CRM**: http://localhost:3010 (Login: `admin@admin.com` / `admin`)
|
||||||
|
- **Datenbank-UI** (Adminer): http://localhost:8081 (Server: `db`, User: `root`, DB: `opencrm`)
|
||||||
|
|
||||||
|
Alle persistenten Daten liegen in `./data/`:
|
||||||
|
|
||||||
|
| Pfad | Inhalt |
|
||||||
|
|------|--------|
|
||||||
|
| `./data/db/` | MariaDB-Datafiles |
|
||||||
|
| `./data/uploads/` | User-Uploads (PDFs, Bilder) |
|
||||||
|
| `./data/factory-defaults/` | Stammdaten-Kataloge |
|
||||||
|
| `./data/backups/` | DB-Backups (`npm run db:backup`) |
|
||||||
|
|
||||||
|
Ports + Pfade konfigurierst du in `./.env` (Default-Werte siehe `.env.example`).
|
||||||
|
|
||||||
|
> **Erste Inbetriebnahme:** In der `.env` einmalig `RUN_SEED=true` setzen,
|
||||||
|
> `docker compose up -d` ausführen, dann wieder auf `false`. Danach existiert
|
||||||
|
> der initiale Admin-User `admin@admin.com` / `admin`.
|
||||||
|
|
||||||
## Voraussetzungen
|
## Voraussetzungen
|
||||||
|
|
||||||
- Node.js 18+ (empfohlen: 20+)
|
- Docker & Docker Compose v2
|
||||||
- Docker & Docker Compose
|
- Für Backend-Entwicklung außerhalb von Docker: Node.js 20+ und npm
|
||||||
- npm
|
|
||||||
|
|
||||||
## Installation
|
## Installation für Entwicklung (ohne Container)
|
||||||
|
|
||||||
### 1. Repository klonen
|
### 1. Repository klonen
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone <repository-url>
|
git clone <repository-url>
|
||||||
cd opencrm
|
cd opencrm
|
||||||
|
cp .env.example .env # Konfiguration anpassen
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. MariaDB-Datenbank starten
|
### 2. MariaDB-Container starten
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker compose up -d db
|
||||||
```
|
```
|
||||||
|
|
||||||
Dies startet einen MariaDB-Container mit:
|
Das startet nur die Datenbank (mit Daten in `./data/db/`).
|
||||||
- **Port:** 3306
|
Konfiguration kommt aus `./.env`:
|
||||||
- **Datenbank:** opencrm
|
|
||||||
- **Root-Passwort:** rootpassword
|
- **Port:** wie in `DB_PORT` (Standard: 3306, intern auf 127.0.0.1)
|
||||||
- **Benutzer:** opencrm / opencrm123
|
- **Datenbank/User/Passwort:** wie in `DB_*`-Variablen
|
||||||
|
|
||||||
Warte ca. 10 Sekunden bis die Datenbank bereit ist.
|
Warte ca. 10 Sekunden bis die Datenbank bereit ist.
|
||||||
|
|
||||||
@@ -185,6 +215,67 @@ Plus:
|
|||||||
- Vollständige Hardening-Story + restliche Trade-offs:
|
- Vollständige Hardening-Story + restliche Trade-offs:
|
||||||
[docs/SECURITY-HARDENING.md](docs/SECURITY-HARDENING.md)
|
[docs/SECURITY-HARDENING.md](docs/SECURITY-HARDENING.md)
|
||||||
|
|
||||||
|
### ⚠️ Wichtig: gzip für `/api/*` am Reverse-Proxy deaktivieren (BREACH-Schutz)
|
||||||
|
|
||||||
|
Wenn ein TLS-Reverse-Proxy (Nginx Proxy Manager, Caddy, eigener Nginx, …) HTTPS
|
||||||
|
terminiert und Antworten gzip-komprimiert, ist die **BREACH-Attacke** (CVE-2013-3587)
|
||||||
|
theoretisch möglich: aus der gzip-komprimierten Response-Größe könnten unter
|
||||||
|
ungünstigen Umständen Secrets erraten werden. Auch wenn unsere JWT-basierte SPA
|
||||||
|
das Risiko praktisch klein hält (keine reflektierten Secrets im Response-Body),
|
||||||
|
geht ein Penetration-Test mit testssl trotzdem auf „medium – Ausnutzbar: Ja".
|
||||||
|
|
||||||
|
**Lösung:** gzip-Komprimierung nur für statische Frontend-Assets erlauben, für
|
||||||
|
`/api/*` deaktivieren. Statische Bundles bleiben damit performant ausgeliefert,
|
||||||
|
JSON-API-Responses werden ohne Kompression gesendet → BREACH ist dort kein
|
||||||
|
Einfallstor mehr.
|
||||||
|
|
||||||
|
**Nginx Proxy Manager (NPM):**
|
||||||
|
1. Proxy-Hosts → den CRM-Host → **Edit**
|
||||||
|
2. Tab **Custom Locations** → **„Add location"**
|
||||||
|
3. **Define location:** `/api/`
|
||||||
|
4. **Scheme:** `http`, **Forward Hostname/IP:** wie im Haupt-Host
|
||||||
|
(z.B. `172.0.2.39`), **Forward Port:** `3010`
|
||||||
|
5. Zahnrad rechts an der Location → erweiterte Config eintragen:
|
||||||
|
```nginx
|
||||||
|
gzip off;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
# Information-Disclosure-Header weg (Pentest-Hygiene):
|
||||||
|
more_clear_headers Server X-Served-By;
|
||||||
|
```
|
||||||
|
6. **Save** (Location), **Save** (Proxy-Host)
|
||||||
|
|
||||||
|
> Der `more_clear_headers`-Befehl kommt aus dem `headers-more`-Modul, das
|
||||||
|
> bei NPM standardmäßig dabei ist. Damit verschwinden die Banner
|
||||||
|
> `Server: openresty` und `x-served-by: …` aus den Responses – Pentest-
|
||||||
|
> Tools können den eingesetzten Webserver nicht mehr direkt aus dem Header
|
||||||
|
> ablesen. Wer das auch auf der Hauptlocation will, kann denselben Eintrag
|
||||||
|
> zusätzlich im **Advanced**-Tab des Proxy-Hosts setzen.
|
||||||
|
|
||||||
|
**Plain Nginx** (falls eigener Nginx statt NPM):
|
||||||
|
```nginx
|
||||||
|
location /api/ {
|
||||||
|
gzip off;
|
||||||
|
proxy_pass http://backend:3010;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
more_clear_headers Server X-Served-By; # braucht headers-more-Modul
|
||||||
|
}
|
||||||
|
# Optional global im server { … }-Block:
|
||||||
|
server_tokens off;
|
||||||
|
```
|
||||||
|
|
||||||
|
**Verifikation:**
|
||||||
|
```bash
|
||||||
|
# 1) gzip ist für /api/ deaktiviert (sollte leer sein)
|
||||||
|
curl -sI -H 'Accept-Encoding: gzip' https://kundencenter.deine-domain.de/api/health \
|
||||||
|
| grep -i content-encoding
|
||||||
|
|
||||||
|
# 2) Server-/x-served-by-Banner sind weg (sollte leer sein)
|
||||||
|
curl -sI https://kundencenter.deine-domain.de/api/health \
|
||||||
|
| grep -iE '^(server|x-served-by):'
|
||||||
|
```
|
||||||
|
|
||||||
## Developer-Tools aktivieren
|
## Developer-Tools aktivieren
|
||||||
|
|
||||||
Die Developer-Tools (Datenbankstruktur, ER-Diagramm) sind standardmäßig für Admins verfügbar. Falls der Menüpunkt nicht erscheint:
|
Die Developer-Tools (Datenbankstruktur, ER-Diagramm) sind standardmäßig für Admins verfügbar. Falls der Menüpunkt nicht erscheint:
|
||||||
@@ -1036,8 +1127,9 @@ Folgende Felder werden in Audit-Logs gefiltert:
|
|||||||
## Factory-Defaults: Stammdaten-Kataloge teilen
|
## Factory-Defaults: Stammdaten-Kataloge teilen
|
||||||
|
|
||||||
Das **Factory-Defaults**-System erlaubt den Export und Import von
|
Das **Factory-Defaults**-System erlaubt den Export und Import von
|
||||||
Stammdaten-Katalogen (Anbieter, Tarife, PDF-Vorlagen usw.) zwischen verschiedenen
|
Stammdaten-Katalogen (Anbieter, Tarife, PDF-Auftragsvorlagen, HTML-Standardtexte)
|
||||||
OpenCRM-Installationen. Es ist bewusst **streng abgegrenzt** zu Datenbank-Backups:
|
zwischen verschiedenen OpenCRM-Installationen. Es ist bewusst **streng abgegrenzt**
|
||||||
|
zu Datenbank-Backups:
|
||||||
|
|
||||||
### Abgrenzung
|
### Abgrenzung
|
||||||
|
|
||||||
@@ -1045,64 +1137,117 @@ OpenCRM-Installationen. Es ist bewusst **streng abgegrenzt** zu Datenbank-Backup
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Anbieter, Tarife, Kündigungsfristen, Laufzeiten, Kategorien | ✅ | ✅ |
|
| Anbieter, Tarife, Kündigungsfristen, Laufzeiten, Kategorien | ✅ | ✅ |
|
||||||
| PDF-Auftragsvorlagen (inkl. Dateien + Feldzuordnungen) | ✅ | ✅ |
|
| PDF-Auftragsvorlagen (inkl. Dateien + Feldzuordnungen) | ✅ | ✅ |
|
||||||
|
| HTML-Standardtexte: Datenschutzerklärung, Impressum, Vollmacht-Vorlage, Website-Datenschutz | ✅ | ✅ |
|
||||||
| **Kundendaten, Verträge, Dokumente** | ❌ | ✅ |
|
| **Kundendaten, Verträge, Dokumente** | ❌ | ✅ |
|
||||||
| **Emails, SMTP-/IMAP-Zugangsdaten** | ❌ | ✅ |
|
| **Emails, SMTP-/IMAP-Zugangsdaten** | ❌ | ✅ |
|
||||||
| **System-Einstellungen, Datenschutzerklärungen, Impressum** | ❌ | ✅ |
|
| **Secrets, JWT, Encryption-Keys, User-Accounts** | ❌ | ✅ |
|
||||||
| Zwischen verschiedenen Installationen teilbar | ✅ | ❌ (zu firmen-spezifisch) |
|
| Zwischen verschiedenen Installationen teilbar | ✅ | ❌ (zu firmen-spezifisch) |
|
||||||
|
|
||||||
> **Kurz:** Factory-Defaults = reine Kataloge, Backup = alles.
|
> **Kurz:** Factory-Defaults = generische Stammdaten + rechtliche Standardtexte,
|
||||||
|
> Backup = die komplette Instanz.
|
||||||
|
|
||||||
### Export (Installation A → ZIP)
|
### Drei Wege, eine ZIP zu transportieren
|
||||||
|
|
||||||
|
Es gibt drei Pfade, je nachdem wo die ZIP gerade liegen soll:
|
||||||
|
|
||||||
|
| Wo | Pfad | Wann |
|
||||||
|
|---|---|---|
|
||||||
|
| **Laufende DB einer Instanz** | UI-Upload oder `./factory-import.sh` | Bestehende Live-Instanz updaten |
|
||||||
|
| **Drop-Box im Repo** (`factory-exports/`) | `./factory-export.sh` legt ab, `./factory-import.sh` liest | Transfer zwischen dev und prod via `scp` |
|
||||||
|
| **Werkseinstellung im Image** (`backend/factory-defaults/`) | `./factory-import.sh --save-as-builtin` oder manuell entpacken | Neue VMs sollen die Defaults beim allerersten Start mitbringen |
|
||||||
|
|
||||||
|
Alle drei sind unabhängig, **alle drei zusammen** decken den typischen Workflow ab.
|
||||||
|
|
||||||
|
### Export
|
||||||
|
|
||||||
|
**Variante A – UI:**
|
||||||
1. **Einstellungen** → **Factory-Defaults** öffnen
|
1. **Einstellungen** → **Factory-Defaults** öffnen
|
||||||
2. Übersicht prüfen (Anzahl pro Kategorie)
|
2. Button **„Factory-Defaults exportieren"** klicken
|
||||||
3. Button **„Factory-Defaults exportieren"** klicken
|
3. ZIP wird als `factory-defaults-YYYY-MM-DD.zip` heruntergeladen
|
||||||
4. ZIP wird als `factory-defaults-YYYY-MM-DD.zip` heruntergeladen
|
|
||||||
|
**Variante B – CLI (für scp-Transfers):**
|
||||||
|
```bash
|
||||||
|
./factory-export.sh # → factory-exports/factory-defaults-…zip
|
||||||
|
OPENCRM_URL=https://crm.prod.example.de \
|
||||||
|
OPENCRM_EMAIL=admin@example.de ./factory-export.sh # gegen Prod-Instanz
|
||||||
|
```
|
||||||
|
Ohne `OPENCRM_PASSWORD` wird das Passwort interaktiv abgefragt. Der Zielordner
|
||||||
|
`factory-exports/` ist gitignored – die ZIPs landen also nicht ins Repo.
|
||||||
|
|
||||||
**ZIP-Struktur:**
|
**ZIP-Struktur:**
|
||||||
```
|
```
|
||||||
factory-defaults-2026-04-23.zip
|
factory-defaults-2026-05-07-1949.zip
|
||||||
├── manifest.json # Version + Datum + Counts
|
├── manifest.json # Version + Datum + Counts
|
||||||
├── providers/
|
├── providers/providers.json
|
||||||
│ └── providers.json # Anbieter inkl. zugehöriger Tarife
|
|
||||||
├── contract-meta/
|
├── contract-meta/
|
||||||
│ ├── cancellation-periods.json # Kündigungsfristen (Code + Beschreibung)
|
│ ├── cancellation-periods.json
|
||||||
│ ├── contract-durations.json # Laufzeiten (Code + Beschreibung)
|
│ ├── contract-durations.json
|
||||||
│ └── contract-categories.json # Kategorien (Strom, Gas, DSL, ...)
|
│ └── contract-categories.json
|
||||||
└── pdf-templates/
|
├── pdf-templates/
|
||||||
├── pdf-templates.json # Vorlagen-Metadaten + Feldzuordnungen
|
│ ├── pdf-templates.json
|
||||||
└── *.pdf # Die eigentlichen PDF-Dateien
|
│ └── *.pdf # Die eigentlichen PDF-Dateien
|
||||||
|
└── app-settings/
|
||||||
|
└── app-settings.json # HTML-Templates (Whitelist-only)
|
||||||
```
|
```
|
||||||
|
|
||||||
Die ZIP kann an andere Installationen weitergegeben werden
|
### Import
|
||||||
(Partner, Test-System, neue Installation).
|
|
||||||
|
|
||||||
### Import (ZIP → Installation B)
|
**Variante A – UI:**
|
||||||
|
1. **Einstellungen** → **Factory-Defaults**
|
||||||
|
2. Bereich **Import** → **„ZIP hochladen"** → Datei wählen
|
||||||
|
3. Erfolgs-Box zeigt Counts pro Kategorie
|
||||||
|
|
||||||
1. ZIP herunterladen bzw. erhalten
|
**Variante B – CLI:**
|
||||||
2. Inhalt nach `backend/factory-defaults/` entpacken (Unterordnerstruktur beibehalten)
|
```bash
|
||||||
3. Im Backend-Verzeichnis ausführen:
|
./factory-import.sh # nimmt jüngste ZIP aus factory-exports/
|
||||||
```bash
|
./factory-import.sh ./factory-exports/foo.zip # explizite ZIP
|
||||||
npm run seed:defaults
|
./factory-import.sh --save-as-builtin # zusätzlich ins Image-Default
|
||||||
```
|
./factory-import.sh --save-as-builtin ./foo.zip # entpacken (siehe unten)
|
||||||
|
```
|
||||||
|
|
||||||
|
Konfigurierbar per ENV: `OPENCRM_URL`, `OPENCRM_EMAIL`, `OPENCRM_PASSWORD`.
|
||||||
|
|
||||||
|
**Variante C – Container-Bare-Metal (für Migration / mehrere ZIPs zusammenführen):**
|
||||||
|
```bash
|
||||||
|
# Inhalt der ZIP nach backend/factory-defaults/ entpacken (Unterordner beibehalten)
|
||||||
|
cd backend && npm run seed:defaults
|
||||||
|
```
|
||||||
|
|
||||||
**Beispiel-Output:**
|
**Beispiel-Output:**
|
||||||
```
|
```
|
||||||
📦 Factory-Defaults werden eingespielt...
|
✓ Anbieter: 10
|
||||||
|
✓ Tarife: 4
|
||||||
✓ Anbieter: 7, Tarife: 12
|
✓ Kündigungsfristen: 18
|
||||||
✓ Kündigungsfristen: 5
|
✓ Laufzeiten: 18
|
||||||
✓ Laufzeiten: 4
|
✓ Vertragskategorien: 8
|
||||||
✓ Vertragskategorien: 8
|
✓ PDF-Vorlagen: 2
|
||||||
✓ PDF-Vorlagen: 3
|
✓ HTML-Templates: 2
|
||||||
|
|
||||||
✅ Factory-Defaults erfolgreich eingespielt.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Mehrere ZIPs kombinieren
|
### `--save-as-builtin`: ZIP zur Werkseinstellung machen
|
||||||
|
|
||||||
Du kannst mehrere Exporte in `backend/factory-defaults/` übereinanderlegen –
|
Mit `--save-as-builtin` entpackt `factory-import.sh` die ZIP nach **erfolgreichem
|
||||||
JSON-Dateien werden automatisch gemerged:
|
DB-Import** zusätzlich in `backend/factory-defaults/`. Beim nächsten
|
||||||
|
`docker-compose up --build` landen die Defaults im Image. Frisch hochgezogene
|
||||||
|
VMs bringen sie dann beim ersten Start automatisch mit (Auto-Seed-Pfad im
|
||||||
|
Container-Entrypoint).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# typischer Sync prod → dev → Image-Default
|
||||||
|
ssh prod './factory-export.sh'
|
||||||
|
scp prod:opencrm/factory-exports/factory-defaults-*.zip factory-exports/
|
||||||
|
./factory-import.sh --save-as-builtin
|
||||||
|
docker-compose up -d --build # neuer Build, neue VMs starten direkt mit Defaults
|
||||||
|
```
|
||||||
|
|
||||||
|
Der Inhalt von `backend/factory-defaults/` wird beim `--save-as-builtin` vorher
|
||||||
|
geleert (außer `README.md` und `.gitkeep`), damit nichts Veraltetes liegen
|
||||||
|
bleibt.
|
||||||
|
|
||||||
|
### Mehrere ZIPs kombinieren (CLI-only, Variante C)
|
||||||
|
|
||||||
|
`backend/factory-defaults/` darf mehrere `*.json` pro Unterordner haben –
|
||||||
|
`npm run seed:defaults` merged sie automatisch:
|
||||||
|
|
||||||
```
|
```
|
||||||
backend/factory-defaults/
|
backend/factory-defaults/
|
||||||
@@ -1112,40 +1257,73 @@ backend/factory-defaults/
|
|||||||
eigene.json # 5 eigene Anbieter
|
eigene.json # 5 eigene Anbieter
|
||||||
```
|
```
|
||||||
|
|
||||||
Das Import-Script liest **alle** `*.json` im jeweiligen Unterordner und merged per
|
Bei gleichem Unique-Key gewinnt der zuletzt gelesene Eintrag. Der UI-/HTTP-Import
|
||||||
unique Key (letzter Eintrag gewinnt). Duplikate sind also unproblematisch.
|
nimmt nur eine ZIP entgegen – für Merges nutze `npm run seed:defaults`.
|
||||||
|
|
||||||
### Idempotenz
|
### Idempotenz
|
||||||
|
|
||||||
Das Script nutzt ausschließlich Prisma `upsert`:
|
Alle Pfade nutzen Prisma `upsert`:
|
||||||
- **Neue Einträge** werden angelegt
|
- **Neue Einträge** werden angelegt
|
||||||
- **Bestehende Einträge** (per unique Key: `name`, `code`) werden aktualisiert
|
- **Bestehende Einträge** (per unique Key: `name` / `code` / `key`) werden aktualisiert
|
||||||
- Nichts wird gelöscht
|
- Nichts wird gelöscht
|
||||||
|
|
||||||
Du kannst `npm run seed:defaults` also beliebig oft ausführen, ohne Datenverlust
|
Du kannst Imports also beliebig oft hintereinander ausführen, ohne Datenverlust
|
||||||
oder Duplikate.
|
oder Duplikate.
|
||||||
|
|
||||||
### PDF-Dateien beim Import
|
### PDF-Dateien
|
||||||
|
|
||||||
Beim Import werden PDF-Vorlagen aus `factory-defaults/pdf-templates/*.pdf` nach
|
Beim Import werden PDF-Vorlagen aus dem ZIP nach `uploads/pdf-templates/`
|
||||||
`uploads/pdf-templates/` kopiert und die Pfade in der DB entsprechend gesetzt.
|
kopiert (mit eindeutigem Suffix) und die `templatePath`-Spalte entsprechend
|
||||||
Beim Re-Import wird die alte Datei in `uploads/` entsorgt und durch die neue
|
gesetzt. Beim Re-Import wird die alte Datei in `uploads/` entsorgt und durch
|
||||||
ersetzt.
|
die neue ersetzt.
|
||||||
|
|
||||||
|
### AppSettings-Whitelist
|
||||||
|
|
||||||
|
Beim Import werden nur die Keys mit AppSetting-Schreibzugriff gewährt, die auch
|
||||||
|
exportiert werden – aktuell:
|
||||||
|
|
||||||
|
- `privacyPolicyHtml`
|
||||||
|
- `imprintHtml`
|
||||||
|
- `authorizationTemplateHtml`
|
||||||
|
- `websitePrivacyPolicyHtml`
|
||||||
|
|
||||||
|
Andere Keys (SMTP, JWT, etc.) werden mit einer Warnung ignoriert. Whitelist ist
|
||||||
|
in [`backend/src/services/factoryDefaults.service.ts`](backend/src/services/factoryDefaults.service.ts)
|
||||||
|
zentral gepflegt.
|
||||||
|
|
||||||
|
### Auto-Seed beim Erst-Deploy
|
||||||
|
|
||||||
|
Bei einer **frischen** Installation (leere DB) spielt der Container-Entrypoint
|
||||||
|
nach dem Prisma-Seed automatisch das Built-in-Verzeichnis ein:
|
||||||
|
|
||||||
|
```
|
||||||
|
[entrypoint] DB ist leer (User-Count=0) – Auto-Seed wird ausgeführt
|
||||||
|
[entrypoint] Spiele eingebaute Factory-Defaults ein…
|
||||||
|
✓ Anbieter: 10, Tarife: 4
|
||||||
|
…
|
||||||
|
```
|
||||||
|
|
||||||
|
Bei bestehenden Installs passiert das **nicht** – nur frische DBs.
|
||||||
|
|
||||||
### Berechtigungen
|
### Berechtigungen
|
||||||
|
|
||||||
| Aktion | Berechtigung |
|
| Aktion | Berechtigung |
|
||||||
|--------|--------------|
|
|--------|--------------|
|
||||||
| Factory-Defaults Vorschau | `settings:read` |
|
| Factory-Defaults Vorschau | `settings:read` |
|
||||||
| Factory-Defaults Export | `settings:update` |
|
| Factory-Defaults Export (UI/CLI) | `settings:update` |
|
||||||
| Factory-Defaults Import (CLI) | Server-Zugang (SSH/Shell) |
|
| Factory-Defaults Import (UI/CLI) | `settings:update` |
|
||||||
|
| Werkseinstellungen ändern (`--save-as-builtin` / `npm run seed:defaults`) | Server-Zugang (SSH/Shell) |
|
||||||
|
|
||||||
### Typischer Einsatzzweck
|
### Typische Einsatzzwecke
|
||||||
|
|
||||||
- **Neue Installation aufsetzen**: Eine Kollegen-ZIP importieren und sofort mit
|
- **Neue VM aufsetzen**: ZIP einmalig nach `backend/factory-defaults/` entpacken
|
||||||
gepflegtem Anbieter- und Vorlagenkatalog loslegen
|
(oder per `--save-as-builtin`), dann `docker-compose up --build` – die
|
||||||
|
Werkseinstellungen sind beim ersten Start automatisch drin.
|
||||||
|
- **Prod-Stand zurück nach dev synchronisieren**: `./factory-export.sh` auf prod,
|
||||||
|
`scp` ins dev, `./factory-import.sh --save-as-builtin` lokal – damit ist
|
||||||
|
sowohl die dev-DB aktuell als auch der nächste Image-Build.
|
||||||
- **Vorlagen-Paket teilen**: Eine ZIP mit nur PDF-Vorlagen weitergeben
|
- **Vorlagen-Paket teilen**: Eine ZIP mit nur PDF-Vorlagen weitergeben
|
||||||
(die anderen Ordner einfach aus der ZIP entfernen vor dem Entpacken)
|
(andere Ordner aus der ZIP entfernen vor dem Entpacken).
|
||||||
- **Anbieter-Paket teilen**: ZIP mit nur `providers/` weitergeben
|
- **Anbieter-Paket teilen**: ZIP mit nur `providers/` weitergeben
|
||||||
- **Versionskontrolle**: Die entpackten JSON-Dateien unter Versionskontrolle
|
- **Versionskontrolle**: Die entpackten JSON-Dateien unter Versionskontrolle
|
||||||
stellen (außerhalb von `backend/factory-defaults/`, da der Ordner gitignored ist)
|
stellen (außerhalb von `backend/factory-defaults/`, da der Ordner gitignored ist)
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# Backend nutzt seit v1.1 die zentrale Root-.env im Projektverzeichnis.
|
||||||
|
# → siehe ../.env.example für alle Variablen
|
||||||
|
#
|
||||||
|
# Diese Datei bleibt als Legacy-Fallback: wenn /.env nicht existiert,
|
||||||
|
# liest das Backend backend/.env (z.B. für isolierte Backend-Tests).
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
DATABASE_URL="mysql://user:password@localhost:3306/opencrm"
|
DATABASE_URL="mysql://user:password@localhost:3306/opencrm"
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,10 +4,11 @@ node_modules/
|
|||||||
# Build
|
# Build
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# Environment
|
# Environment – echte Secrets blocken, .env.example weiter mittracken
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
!.env.example
|
||||||
|
|
||||||
# Database Backups (can be large, keep folder structure)
|
# Database Backups (can be large, keep folder structure)
|
||||||
prisma/backups/*
|
prisma/backups/*
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
# Multi-Stage Build: Frontend bauen, dann Backend bauen, dann schlankes Runtime-Image
|
||||||
|
# ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Alle Stages auf node:20-slim (Debian-basiert) – dann passt die Prisma-Query-
|
||||||
|
# Engine (glibc + openssl) zur Runtime.
|
||||||
|
|
||||||
|
# ============== STAGE 1: Frontend bauen ==============
|
||||||
|
FROM node:20-slim AS frontend-builder
|
||||||
|
WORKDIR /build/frontend
|
||||||
|
COPY frontend/package.json frontend/package-lock.json ./
|
||||||
|
RUN npm ci --no-audit --no-fund --prefer-offline
|
||||||
|
COPY frontend/ ./
|
||||||
|
RUN npm run build
|
||||||
|
# Output: /build/frontend/dist/
|
||||||
|
|
||||||
|
# ============== STAGE 2: Backend bauen (TS → JS) ==============
|
||||||
|
FROM node:20-slim AS backend-builder
|
||||||
|
WORKDIR /build/backend
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends openssl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY backend/package.json backend/package-lock.json ./
|
||||||
|
RUN npm ci --no-audit --no-fund --prefer-offline
|
||||||
|
COPY backend/prisma ./prisma
|
||||||
|
RUN npx prisma generate
|
||||||
|
COPY backend/tsconfig.json ./
|
||||||
|
COPY backend/src ./src
|
||||||
|
RUN npx tsc
|
||||||
|
# Output: /build/backend/dist/
|
||||||
|
|
||||||
|
# ============== STAGE 3: Runtime ==============
|
||||||
|
# Debian-slim statt Alpine: Prisma-Engines erwarten libssl 1.1, das in Alpine 3.19+
|
||||||
|
# nicht mehr verfügbar ist. Slim hat openssl 3 ABI-kompatibel + native binaries.
|
||||||
|
FROM node:20-slim
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# OpenSSL für Prisma-Query-Engine + wget für Healthcheck
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends openssl wget \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Nur Production-Dependencies + Prisma-Client
|
||||||
|
COPY backend/package.json backend/package-lock.json ./
|
||||||
|
RUN npm ci --omit=dev --no-audit --no-fund --prefer-offline && npm cache clean --force
|
||||||
|
|
||||||
|
# Build-Artefakte aus Stage 2
|
||||||
|
COPY --from=backend-builder /build/backend/dist ./dist
|
||||||
|
COPY --from=backend-builder /build/backend/node_modules/.prisma ./node_modules/.prisma
|
||||||
|
COPY --from=backend-builder /build/backend/node_modules/@prisma ./node_modules/@prisma
|
||||||
|
COPY backend/prisma ./prisma
|
||||||
|
|
||||||
|
# Frontend-Build ins public/-Verzeichnis (wird in production-Mode statisch ausgeliefert)
|
||||||
|
COPY --from=frontend-builder /build/frontend/dist ./public
|
||||||
|
|
||||||
|
# Eingebaute Werkseinstellungen ins Image: bei Erstinstallation (leerer DB) zieht
|
||||||
|
# der Entrypoint sie via tsx scripts/seed-factory-defaults.ts ein. Liegt in einem
|
||||||
|
# eigenen Pfad – `factory-defaults/` selbst kann über Bind-Mount überlagert werden.
|
||||||
|
COPY backend/factory-defaults /app/factory-defaults-builtin
|
||||||
|
COPY backend/scripts /app/scripts
|
||||||
|
|
||||||
|
# Daten-Verzeichnisse (werden via Bind-Mount überlagert; hier nur als Fallback)
|
||||||
|
RUN mkdir -p uploads factory-defaults prisma/backups
|
||||||
|
|
||||||
|
# Healthcheck
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||||
|
CMD wget --quiet --tries=1 --spider "http://localhost:${PORT:-3001}/api/health" || exit 1
|
||||||
|
|
||||||
|
# Beim Start: prisma db push (idempotent), dann node
|
||||||
|
COPY backend/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
|
CMD ["node", "dist/index.js"]
|
||||||
Executable
+126
@@ -0,0 +1,126 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Container-Start:
|
||||||
|
# 1) Auf DB warten
|
||||||
|
# 2) Auto-Baseline für bestehende DBs (db-push-Ära ohne _prisma_migrations)
|
||||||
|
# 3) `prisma migrate deploy` (idempotent, datenerhaltend)
|
||||||
|
# 4) Auto-Seed bei leerer User-Tabelle (oder RUN_SEED=true)
|
||||||
|
# Neue Schema-Änderung anlegen (lokal, im Dev): npm run schema:sync
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# DATABASE_URL aus DB_*-Komponenten bauen, falls nicht explizit gesetzt.
|
||||||
|
# Wichtig: encodeURIComponent für DB_USER + DB_PASSWORD, damit Sonderzeichen
|
||||||
|
# wie $, !, #, @, :, / etc. nicht die URL-Authority-Syntax brechen.
|
||||||
|
# Wir nutzen node-eval (ist eh installiert), kein extra-Tool wie jq nötig.
|
||||||
|
if [ -z "$DATABASE_URL" ] && [ -n "$DB_USER" ] && [ -n "$DB_PASSWORD" ] && [ -n "$DB_NAME" ]; then
|
||||||
|
DATABASE_URL=$(node -e "
|
||||||
|
const u = encodeURIComponent(process.env.DB_USER);
|
||||||
|
const p = encodeURIComponent(process.env.DB_PASSWORD);
|
||||||
|
const h = process.env.DB_HOST || 'db';
|
||||||
|
const port = process.env.DB_PORT || '3306';
|
||||||
|
const n = process.env.DB_NAME;
|
||||||
|
process.stdout.write(\`mysql://\${u}:\${p}@\${h}:\${port}/\${n}\`);
|
||||||
|
")
|
||||||
|
export DATABASE_URL
|
||||||
|
echo "[entrypoint] DATABASE_URL aus DB_*-Komponenten gebaut (host=${DB_HOST:-db})"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[entrypoint] Warte auf Datenbank…"
|
||||||
|
# Erst auf DB-Verfügbarkeit warten via einfachem Connect-Check.
|
||||||
|
# Wir nutzen Prisma's interne Engine, kein extra mysql-client nötig.
|
||||||
|
TRIES=30
|
||||||
|
until node -e "
|
||||||
|
const { PrismaClient } = require('@prisma/client');
|
||||||
|
const p = new PrismaClient();
|
||||||
|
p.\$queryRaw\`SELECT 1\`
|
||||||
|
.then(() => p.\$disconnect().then(() => process.exit(0)))
|
||||||
|
.catch(() => process.exit(1));
|
||||||
|
" 2>/dev/null; do
|
||||||
|
TRIES=$((TRIES - 1))
|
||||||
|
if [ "$TRIES" -le 0 ]; then
|
||||||
|
echo "[entrypoint] DB nicht erreichbar – Abbruch"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[entrypoint] DB noch nicht bereit – retry in 2s ($TRIES Versuche übrig)"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "[entrypoint] DB erreichbar"
|
||||||
|
|
||||||
|
# Auto-Baseline: Wenn die DB Anwendungs-Tabellen enthält (z.B. User), aber noch
|
||||||
|
# keine _prisma_migrations-Tabelle, dann ist es eine "alte" DB, die früher mit
|
||||||
|
# `prisma db push` synced wurde. Wir markieren 0_init als bereits angewendet,
|
||||||
|
# damit `migrate deploy` nicht versucht, alle Tabellen nochmal anzulegen.
|
||||||
|
NEEDS_BASELINE=$(node -e "
|
||||||
|
const { PrismaClient } = require('@prisma/client');
|
||||||
|
const p = new PrismaClient();
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const dbName = process.env.DB_NAME;
|
||||||
|
const tables = await p.\$queryRawUnsafe(
|
||||||
|
\`SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = ?\`,
|
||||||
|
dbName
|
||||||
|
);
|
||||||
|
const names = tables.map(t => t.TABLE_NAME);
|
||||||
|
const hasMigrations = names.includes('_prisma_migrations');
|
||||||
|
const hasUserTable = names.includes('User');
|
||||||
|
// Existing DB (User da) ohne Migrations-Tracking => Baseline nötig
|
||||||
|
if (hasUserTable && !hasMigrations) process.stdout.write('yes');
|
||||||
|
else process.stdout.write('no');
|
||||||
|
} catch (e) {
|
||||||
|
process.stdout.write('no');
|
||||||
|
} finally {
|
||||||
|
await p.\$disconnect();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "$NEEDS_BASELINE" = "yes" ]; then
|
||||||
|
echo "[entrypoint] Bestehende DB ohne Migrations-Tracking erkannt – markiere 0_init als angewendet (Baseline)"
|
||||||
|
npx prisma migrate resolve --applied 0_init || echo "[entrypoint] Baseline fehlgeschlagen – fahre trotzdem fort"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Migrations anwenden (idempotent: bereits angewendete werden übersprungen).
|
||||||
|
# Im Gegensatz zu `db push` löscht `migrate deploy` keine Daten — Schema-
|
||||||
|
# Änderungen werden über versionierte Migrations-Files unter prisma/migrations/
|
||||||
|
# eingespielt. Neue Migration anlegen mit: npm run schema:sync (lokal, dev).
|
||||||
|
echo "[entrypoint] Wende Migrations an…"
|
||||||
|
if ! npx prisma migrate deploy; then
|
||||||
|
echo "[entrypoint] migrate deploy fehlgeschlagen – Abbruch"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[entrypoint] DB-Schema aktuell"
|
||||||
|
|
||||||
|
# Auto-Seed: wenn die User-Tabelle leer ist (= Erstinstallation), automatisch seeden.
|
||||||
|
# RUN_SEED=true erzwingt Seed auch bei nicht-leerer DB (z.B. nach Reset).
|
||||||
|
USER_COUNT=$(node -e "
|
||||||
|
const { PrismaClient } = require('@prisma/client');
|
||||||
|
const p = new PrismaClient();
|
||||||
|
p.user.count()
|
||||||
|
.then((n) => { process.stdout.write(String(n)); process.exit(0); })
|
||||||
|
.catch(() => { process.stdout.write('-1'); process.exit(0); });
|
||||||
|
" 2>/dev/null)
|
||||||
|
|
||||||
|
RAN_SEED=false
|
||||||
|
if [ "${RUN_SEED:-false}" = "true" ]; then
|
||||||
|
echo "[entrypoint] RUN_SEED=true – seede DB (Force)"
|
||||||
|
if npx prisma db seed; then RAN_SEED=true; else echo "[entrypoint] Seed fehlgeschlagen oder schon gelaufen – ignoriert"; fi
|
||||||
|
elif [ "$USER_COUNT" = "0" ]; then
|
||||||
|
echo "[entrypoint] DB ist leer (User-Count=0) – Auto-Seed wird ausgeführt"
|
||||||
|
if npx prisma db seed; then RAN_SEED=true; else echo "[entrypoint] Auto-Seed fehlgeschlagen – ignoriert"; fi
|
||||||
|
else
|
||||||
|
echo "[entrypoint] DB enthält $USER_COUNT User – kein Seed nötig"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Eingebaute Factory-Defaults nach Erstinstallation einspielen.
|
||||||
|
# Das ist die Werkseinstellung für neue VMs: PDF-Vorlagen, Anbieter, Tarife,
|
||||||
|
# HTML-Templates – alles aus /app/factory-defaults-builtin/. Erfolgt nur wenn
|
||||||
|
# der Auto-Seed gerade lief (= frische DB), sonst werden Updates auf
|
||||||
|
# bestehenden Installationen nicht ungewollt überschrieben.
|
||||||
|
if [ "$RAN_SEED" = "true" ] && [ -d /app/factory-defaults-builtin ] \
|
||||||
|
&& [ -n "$(ls -A /app/factory-defaults-builtin 2>/dev/null | grep -v -E '^(README\.md|\.gitkeep)$')" ]; then
|
||||||
|
echo "[entrypoint] Spiele eingebaute Factory-Defaults ein…"
|
||||||
|
FACTORY_DEFAULTS_DIR=/app/factory-defaults-builtin npx tsx scripts/seed-factory-defaults.ts \
|
||||||
|
|| echo "[entrypoint] Factory-Defaults-Seed fehlgeschlagen – ignoriert"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[entrypoint] Starte Backend…"
|
||||||
|
exec "$@"
|
||||||
@@ -18,15 +18,21 @@ backend/factory-defaults/
|
|||||||
│ ├── cancellation-periods.json # Kündigungsfristen
|
│ ├── cancellation-periods.json # Kündigungsfristen
|
||||||
│ ├── contract-durations.json # Vertragslaufzeiten
|
│ ├── contract-durations.json # Vertragslaufzeiten
|
||||||
│ └── contract-categories.json # Vertragskategorien (Strom/Gas/DSL/...)
|
│ └── contract-categories.json # Vertragskategorien (Strom/Gas/DSL/...)
|
||||||
└── pdf-templates/
|
├── pdf-templates/
|
||||||
├── pdf-templates.json # Metadaten + Feldzuordnungen
|
│ ├── pdf-templates.json # Metadaten + Feldzuordnungen
|
||||||
└── *.pdf # PDF-Vorlagen-Dateien
|
│ └── *.pdf # PDF-Vorlagen-Dateien
|
||||||
|
└── app-settings/
|
||||||
|
└── app-settings.json # HTML-Templates: Datenschutz / Impressum /
|
||||||
|
# Vollmacht / Website-Datenschutz
|
||||||
```
|
```
|
||||||
|
|
||||||
**Was NICHT enthalten ist:** Kundendaten, Verträge, Dokumente, E-Mails, SMTP-Einstellungen,
|
**Was NICHT enthalten ist:** Kundendaten, Verträge, Dokumente, E-Mails, SMTP-Einstellungen,
|
||||||
Datenschutzerklärungen oder andere AppSettings. Dafür gibt es den separaten
|
Secrets oder benutzerspezifische AppSettings. Dafür gibt es den separaten
|
||||||
**Datenbank-Backup-Export** (Einstellungen → Datenbank & Zurücksetzen).
|
**Datenbank-Backup-Export** (Einstellungen → Datenbank & Zurücksetzen).
|
||||||
|
|
||||||
|
Bei den AppSettings ist nur eine **Whitelist** vorgesehen (HTML-Texte für rechtliche
|
||||||
|
Standardpflichten) – andere Keys werden beim Import ignoriert.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Export (aus einer bestehenden Installation)
|
## Export (aus einer bestehenden Installation)
|
||||||
@@ -46,7 +52,8 @@ factory-defaults-2026-04-23.zip
|
|||||||
├── contract-meta/contract-durations.json
|
├── contract-meta/contract-durations.json
|
||||||
├── contract-meta/contract-categories.json
|
├── contract-meta/contract-categories.json
|
||||||
├── pdf-templates/pdf-templates.json
|
├── pdf-templates/pdf-templates.json
|
||||||
└── pdf-templates/*.pdf
|
├── pdf-templates/*.pdf
|
||||||
|
└── app-settings/app-settings.json
|
||||||
```
|
```
|
||||||
|
|
||||||
Die ZIP kann an andere Installationen weitergegeben werden – z.B. für Test-Systeme,
|
Die ZIP kann an andere Installationen weitergegeben werden – z.B. für Test-Systeme,
|
||||||
@@ -56,7 +63,15 @@ neue Installationen oder Partner-Setups.
|
|||||||
|
|
||||||
## Import (in eine andere Installation)
|
## Import (in eine andere Installation)
|
||||||
|
|
||||||
### Schritt-für-Schritt
|
### Variante A: Über die UI (empfohlen)
|
||||||
|
|
||||||
|
1. Im Ziel-CRM als Admin einloggen
|
||||||
|
2. **Einstellungen → Factory-Defaults**
|
||||||
|
3. Im Bereich **Import** auf **„ZIP hochladen"** klicken
|
||||||
|
4. Die exportierte ZIP wählen – der Import läuft direkt
|
||||||
|
5. Erfolgsmeldung zeigt Counts pro Kategorie an
|
||||||
|
|
||||||
|
### Variante B: Über die CLI (für Bare-Metal / Migration / mehrere ZIPs zusammenführen)
|
||||||
|
|
||||||
1. **ZIP herunterladen** (aus einer Export-Installation oder von einer Vorlage)
|
1. **ZIP herunterladen** (aus einer Export-Installation oder von einer Vorlage)
|
||||||
2. **Inhalt entpacken** in diesen Ordner (`backend/factory-defaults/`),
|
2. **Inhalt entpacken** in diesen Ordner (`backend/factory-defaults/`),
|
||||||
@@ -234,6 +249,24 @@ Array von Providern, jeweils inkl. zugehöriger Tarife:
|
|||||||
**Unique Key:** `name`
|
**Unique Key:** `name`
|
||||||
**Wichtig:** Die `pdfFilename` muss zu einer PDF-Datei im selben Ordner passen.
|
**Wichtig:** Die `pdfFilename` muss zu einer PDF-Datei im selben Ordner passen.
|
||||||
|
|
||||||
|
### `app-settings/app-settings.json`
|
||||||
|
|
||||||
|
HTML-Standardtexte als Werkseinstellung. Es ist eine **Whitelist** aktiv – andere Keys
|
||||||
|
werden beim Import ignoriert (Schutz vor versehentlichem Überschreiben von Secrets).
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{ "key": "privacyPolicyHtml", "value": "<h1>Datenschutzerklärung</h1>..." },
|
||||||
|
{ "key": "imprintHtml", "value": "<h1>Impressum</h1>..." },
|
||||||
|
{ "key": "authorizationTemplateHtml","value": "<h1>Vollmacht</h1>..." },
|
||||||
|
{ "key": "websitePrivacyPolicyHtml", "value": "<h1>Website-Datenschutz</h1>..." }
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Unique Key:** `key`
|
||||||
|
**Erlaubte Keys:** `privacyPolicyHtml`, `imprintHtml`, `authorizationTemplateHtml`,
|
||||||
|
`websitePrivacyPolicyHtml`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Berechtigungen
|
## Berechtigungen
|
||||||
@@ -242,6 +275,7 @@ Array von Providern, jeweils inkl. zugehöriger Tarife:
|
|||||||
|--------|--------------|
|
|--------|--------------|
|
||||||
| Factory-Defaults Vorschau | `settings:read` |
|
| Factory-Defaults Vorschau | `settings:read` |
|
||||||
| Factory-Defaults Export (UI) | `settings:update` |
|
| Factory-Defaults Export (UI) | `settings:update` |
|
||||||
|
| Factory-Defaults Import (UI) | `settings:update` |
|
||||||
| Factory-Defaults Import (CLI) | Server-Zugang (SSH/Shell) |
|
| Factory-Defaults Import (CLI) | Server-Zugang (SSH/Shell) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Generated
+31
-34
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "opencrm-backend",
|
"name": "opencrm-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "opencrm-backend",
|
"name": "opencrm-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^5.22.0",
|
"@prisma/client": "^5.22.0",
|
||||||
"adm-zip": "^0.5.16",
|
"adm-zip": "^0.5.16",
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
"dotenv-expand": "^13.0.0",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"express-rate-limit": "^8.4.0",
|
"express-rate-limit": "^8.4.0",
|
||||||
"express-validator": "^7.2.0",
|
"express-validator": "^7.2.0",
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
"nodemailer": "^7.0.13",
|
"nodemailer": "^7.0.13",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdfkit": "^0.17.2",
|
"pdfkit": "^0.17.2",
|
||||||
|
"tsx": "^4.19.2",
|
||||||
"undici": "^6.23.0"
|
"undici": "^6.23.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -42,7 +44,6 @@
|
|||||||
"@types/nodemailer": "^7.0.9",
|
"@types/nodemailer": "^7.0.9",
|
||||||
"@types/pdfkit": "^0.17.4",
|
"@types/pdfkit": "^0.17.4",
|
||||||
"prisma": "^5.22.0",
|
"prisma": "^5.22.0",
|
||||||
"tsx": "^4.19.2",
|
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -53,7 +54,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"aix"
|
"aix"
|
||||||
@@ -69,7 +69,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
@@ -85,7 +84,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
@@ -101,7 +99,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
@@ -117,7 +114,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
@@ -133,7 +129,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
@@ -149,7 +144,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"freebsd"
|
"freebsd"
|
||||||
@@ -165,7 +159,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"freebsd"
|
"freebsd"
|
||||||
@@ -181,7 +174,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -197,7 +189,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -213,7 +204,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ia32"
|
"ia32"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -229,7 +219,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -245,7 +234,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"mips64el"
|
"mips64el"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -261,7 +249,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -277,7 +264,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -293,7 +279,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"s390x"
|
"s390x"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -309,7 +294,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -325,7 +309,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"netbsd"
|
"netbsd"
|
||||||
@@ -341,7 +324,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"netbsd"
|
"netbsd"
|
||||||
@@ -357,7 +339,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"openbsd"
|
"openbsd"
|
||||||
@@ -373,7 +354,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"openbsd"
|
"openbsd"
|
||||||
@@ -389,7 +369,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"openharmony"
|
"openharmony"
|
||||||
@@ -405,7 +384,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"sunos"
|
"sunos"
|
||||||
@@ -421,7 +399,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
@@ -437,7 +414,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ia32"
|
"ia32"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
@@ -453,7 +429,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
@@ -1463,6 +1438,33 @@
|
|||||||
"url": "https://dotenvx.com"
|
"url": "https://dotenvx.com"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dotenv-expand": {
|
||||||
|
"version": "13.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-13.0.0.tgz",
|
||||||
|
"integrity": "sha512-aBfBS8eYIeXmpHI9ThIlA7/WLq+SLt18iXUZhb52rW89QLKQFoIpPG1bPeewoPZsTyjSSO3T7234FBVUM1V2rA==",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^17.4.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/dotenv-expand/node_modules/dotenv": {
|
||||||
|
"version": "17.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz",
|
||||||
|
"integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dunder-proto": {
|
"node_modules/dunder-proto": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||||
@@ -1557,7 +1559,6 @@
|
|||||||
"version": "0.27.2",
|
"version": "0.27.2",
|
||||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.2.tgz",
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.2.tgz",
|
||||||
"integrity": "sha512-HyNQImnsOC7X9PMNaCIeAm4ISCQXs5a5YasTXVliKv4uuBo1dKrG0A+uQS8M5eXjVMnLg3WgXaKvprHlFJQffw==",
|
"integrity": "sha512-HyNQImnsOC7X9PMNaCIeAm4ISCQXs5a5YasTXVliKv4uuBo1dKrG0A+uQS8M5eXjVMnLg3WgXaKvprHlFJQffw==",
|
||||||
"dev": true,
|
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"esbuild": "bin/esbuild"
|
"esbuild": "bin/esbuild"
|
||||||
@@ -1784,7 +1785,6 @@
|
|||||||
"version": "2.3.3",
|
"version": "2.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||||
"dev": true,
|
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1841,7 +1841,6 @@
|
|||||||
"version": "4.13.0",
|
"version": "4.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz",
|
||||||
"integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==",
|
"integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"resolve-pkg-maps": "^1.0.0"
|
"resolve-pkg-maps": "^1.0.0"
|
||||||
},
|
},
|
||||||
@@ -2867,7 +2866,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
|
||||||
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
|
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
|
||||||
"dev": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
|
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
|
||||||
}
|
}
|
||||||
@@ -3315,7 +3313,6 @@
|
|||||||
"version": "4.21.0",
|
"version": "4.21.0",
|
||||||
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz",
|
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz",
|
||||||
"integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==",
|
"integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "~0.27.0",
|
"esbuild": "~0.27.0",
|
||||||
"get-tsconfig": "^4.7.5"
|
"get-tsconfig": "^4.7.5"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "OpenCRM Backend API",
|
"description": "OpenCRM Backend API",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "tsx prisma/seed.ts"
|
"seed": "npx tsx prisma/seed.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx watch src/index.ts",
|
"dev": "tsx watch src/index.ts",
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"start": "node dist/index.js",
|
"start": "node dist/index.js",
|
||||||
"db:migrate": "prisma migrate dev",
|
"db:migrate": "prisma migrate dev",
|
||||||
"db:push": "prisma db push",
|
"db:push": "prisma db push",
|
||||||
|
"schema:sync": "prisma migrate dev --name auto_$(date +%Y%m%d_%H%M%S)",
|
||||||
"db:seed": "tsx prisma/seed.ts",
|
"db:seed": "tsx prisma/seed.ts",
|
||||||
"db:studio": "prisma studio",
|
"db:studio": "prisma studio",
|
||||||
"db:backup": "tsx prisma/backup-data.ts",
|
"db:backup": "tsx prisma/backup-data.ts",
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
"dotenv-expand": "^13.0.0",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"express-rate-limit": "^8.4.0",
|
"express-rate-limit": "^8.4.0",
|
||||||
"express-validator": "^7.2.0",
|
"express-validator": "^7.2.0",
|
||||||
@@ -37,6 +39,7 @@
|
|||||||
"nodemailer": "^7.0.13",
|
"nodemailer": "^7.0.13",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdfkit": "^0.17.2",
|
"pdfkit": "^0.17.2",
|
||||||
|
"tsx": "^4.19.2",
|
||||||
"undici": "^6.23.0"
|
"undici": "^6.23.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -53,7 +56,6 @@
|
|||||||
"@types/nodemailer": "^7.0.9",
|
"@types/nodemailer": "^7.0.9",
|
||||||
"@types/pdfkit": "^0.17.4",
|
"@types/pdfkit": "^0.17.4",
|
||||||
"prisma": "^5.22.0",
|
"prisma": "^5.22.0",
|
||||||
"tsx": "^4.19.2",
|
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,989 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `PdfTemplate` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`description` VARCHAR(191) NULL,
|
||||||
|
`providerName` VARCHAR(191) NULL,
|
||||||
|
`templatePath` VARCHAR(191) NOT NULL,
|
||||||
|
`originalName` VARCHAR(191) NOT NULL,
|
||||||
|
`fieldMapping` LONGTEXT NOT NULL,
|
||||||
|
`phoneFieldPrefix` VARCHAR(191) NULL,
|
||||||
|
`maxPhoneFields` INTEGER NULL DEFAULT 8,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `PdfTemplate_name_key`(`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `EmailLog` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`fromAddress` VARCHAR(191) NOT NULL,
|
||||||
|
`toAddress` VARCHAR(191) NOT NULL,
|
||||||
|
`subject` VARCHAR(191) NOT NULL,
|
||||||
|
`context` VARCHAR(191) NOT NULL,
|
||||||
|
`customerId` INTEGER NULL,
|
||||||
|
`triggeredBy` VARCHAR(191) NULL,
|
||||||
|
`smtpServer` VARCHAR(191) NOT NULL,
|
||||||
|
`smtpPort` INTEGER NOT NULL,
|
||||||
|
`smtpEncryption` VARCHAR(191) NOT NULL,
|
||||||
|
`smtpUser` VARCHAR(191) NOT NULL,
|
||||||
|
`success` BOOLEAN NOT NULL,
|
||||||
|
`messageId` VARCHAR(191) NULL,
|
||||||
|
`errorMessage` TEXT NULL,
|
||||||
|
`smtpResponse` TEXT NULL,
|
||||||
|
`sentAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
INDEX `EmailLog_sentAt_idx`(`sentAt`),
|
||||||
|
INDEX `EmailLog_customerId_idx`(`customerId`),
|
||||||
|
INDEX `EmailLog_success_idx`(`success`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `AppSetting` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`key` VARCHAR(191) NOT NULL,
|
||||||
|
`value` TEXT NOT NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `AppSetting_key_key`(`key`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `User` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`email` VARCHAR(191) NOT NULL,
|
||||||
|
`password` VARCHAR(191) NOT NULL,
|
||||||
|
`firstName` VARCHAR(191) NOT NULL,
|
||||||
|
`lastName` VARCHAR(191) NOT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`tokenInvalidatedAt` DATETIME(3) NULL,
|
||||||
|
`passwordResetToken` VARCHAR(191) NULL,
|
||||||
|
`passwordResetExpiresAt` DATETIME(3) NULL,
|
||||||
|
`whatsappNumber` VARCHAR(191) NULL,
|
||||||
|
`telegramUsername` VARCHAR(191) NULL,
|
||||||
|
`signalNumber` VARCHAR(191) NULL,
|
||||||
|
`customerId` INTEGER NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `User_email_key`(`email`),
|
||||||
|
UNIQUE INDEX `User_passwordResetToken_key`(`passwordResetToken`),
|
||||||
|
UNIQUE INDEX `User_customerId_key`(`customerId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Role` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`description` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Role_name_key`(`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Permission` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`resource` VARCHAR(191) NOT NULL,
|
||||||
|
`action` VARCHAR(191) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Permission_resource_action_key`(`resource`, `action`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `RolePermission` (
|
||||||
|
`roleId` INTEGER NOT NULL,
|
||||||
|
`permissionId` INTEGER NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`roleId`, `permissionId`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `UserRole` (
|
||||||
|
`userId` INTEGER NOT NULL,
|
||||||
|
`roleId` INTEGER NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`userId`, `roleId`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Customer` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`type` ENUM('PRIVATE', 'BUSINESS') NOT NULL DEFAULT 'PRIVATE',
|
||||||
|
`salutation` VARCHAR(191) NULL,
|
||||||
|
`firstName` VARCHAR(191) NOT NULL,
|
||||||
|
`lastName` VARCHAR(191) NOT NULL,
|
||||||
|
`companyName` VARCHAR(191) NULL,
|
||||||
|
`foundingDate` DATETIME(3) NULL,
|
||||||
|
`birthDate` DATETIME(3) NULL,
|
||||||
|
`birthPlace` VARCHAR(191) NULL,
|
||||||
|
`email` VARCHAR(191) NULL,
|
||||||
|
`phone` VARCHAR(191) NULL,
|
||||||
|
`mobile` VARCHAR(191) NULL,
|
||||||
|
`taxNumber` VARCHAR(191) NULL,
|
||||||
|
`businessRegistrationPath` VARCHAR(191) NULL,
|
||||||
|
`commercialRegisterPath` VARCHAR(191) NULL,
|
||||||
|
`commercialRegisterNumber` VARCHAR(191) NULL,
|
||||||
|
`privacyPolicyPath` VARCHAR(191) NULL,
|
||||||
|
`consentHash` VARCHAR(191) NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`portalEnabled` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`portalEmail` VARCHAR(191) NULL,
|
||||||
|
`portalPasswordHash` VARCHAR(191) NULL,
|
||||||
|
`portalPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`portalLastLogin` DATETIME(3) NULL,
|
||||||
|
`portalPasswordResetToken` VARCHAR(191) NULL,
|
||||||
|
`portalPasswordResetExpiresAt` DATETIME(3) NULL,
|
||||||
|
`portalTokenInvalidatedAt` DATETIME(3) NULL,
|
||||||
|
`lastBirthdayGreetingYear` INTEGER NULL,
|
||||||
|
`useInformalAddress` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`autoBirthdayGreeting` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`autoBirthdayChannel` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Customer_customerNumber_key`(`customerNumber`),
|
||||||
|
UNIQUE INDEX `Customer_consentHash_key`(`consentHash`),
|
||||||
|
UNIQUE INDEX `Customer_portalEmail_key`(`portalEmail`),
|
||||||
|
UNIQUE INDEX `Customer_portalPasswordResetToken_key`(`portalPasswordResetToken`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `CustomerRepresentative` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`representativeId` INTEGER NOT NULL,
|
||||||
|
`notes` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `CustomerRepresentative_customerId_representativeId_key`(`customerId`, `representativeId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `RepresentativeAuthorization` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`representativeId` INTEGER NOT NULL,
|
||||||
|
`isGranted` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`grantedAt` DATETIME(3) NULL,
|
||||||
|
`withdrawnAt` DATETIME(3) NULL,
|
||||||
|
`source` VARCHAR(191) NULL,
|
||||||
|
`documentPath` VARCHAR(191) NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `RepresentativeAuthorization_customerId_representativeId_key`(`customerId`, `representativeId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Address` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`type` ENUM('DELIVERY_RESIDENCE', 'BILLING') NOT NULL DEFAULT 'DELIVERY_RESIDENCE',
|
||||||
|
`street` VARCHAR(191) NOT NULL,
|
||||||
|
`houseNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`postalCode` VARCHAR(191) NOT NULL,
|
||||||
|
`city` VARCHAR(191) NOT NULL,
|
||||||
|
`country` VARCHAR(191) NOT NULL DEFAULT 'Deutschland',
|
||||||
|
`isDefault` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`ownerCompany` VARCHAR(191) NULL,
|
||||||
|
`ownerFirstName` VARCHAR(191) NULL,
|
||||||
|
`ownerLastName` VARCHAR(191) NULL,
|
||||||
|
`ownerStreet` VARCHAR(191) NULL,
|
||||||
|
`ownerHouseNumber` VARCHAR(191) NULL,
|
||||||
|
`ownerPostalCode` VARCHAR(191) NULL,
|
||||||
|
`ownerCity` VARCHAR(191) NULL,
|
||||||
|
`ownerPhone` VARCHAR(191) NULL,
|
||||||
|
`ownerMobile` VARCHAR(191) NULL,
|
||||||
|
`ownerEmail` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `BankCard` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`accountHolder` VARCHAR(191) NOT NULL,
|
||||||
|
`iban` VARCHAR(191) NOT NULL,
|
||||||
|
`bic` VARCHAR(191) NULL,
|
||||||
|
`bankName` VARCHAR(191) NULL,
|
||||||
|
`expiryDate` DATETIME(3) NULL,
|
||||||
|
`documentPath` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `IdentityDocument` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`type` ENUM('ID_CARD', 'PASSPORT', 'DRIVERS_LICENSE', 'OTHER') NOT NULL DEFAULT 'ID_CARD',
|
||||||
|
`documentNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`issuingAuthority` VARCHAR(191) NULL,
|
||||||
|
`issueDate` DATETIME(3) NULL,
|
||||||
|
`expiryDate` DATETIME(3) NULL,
|
||||||
|
`documentPath` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`licenseClasses` VARCHAR(191) NULL,
|
||||||
|
`licenseIssueDate` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `EmailProviderConfig` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`type` ENUM('PLESK', 'CPANEL', 'DIRECTADMIN') NOT NULL,
|
||||||
|
`apiUrl` VARCHAR(191) NOT NULL,
|
||||||
|
`apiKey` VARCHAR(191) NULL,
|
||||||
|
`username` VARCHAR(191) NULL,
|
||||||
|
`passwordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`domain` VARCHAR(191) NOT NULL,
|
||||||
|
`defaultForwardEmail` VARCHAR(191) NULL,
|
||||||
|
`imapServer` VARCHAR(191) NULL,
|
||||||
|
`imapPort` INTEGER NULL DEFAULT 993,
|
||||||
|
`smtpServer` VARCHAR(191) NULL,
|
||||||
|
`smtpPort` INTEGER NULL DEFAULT 465,
|
||||||
|
`imapEncryption` ENUM('SSL', 'STARTTLS', 'NONE') NOT NULL DEFAULT 'SSL',
|
||||||
|
`smtpEncryption` ENUM('SSL', 'STARTTLS', 'NONE') NOT NULL DEFAULT 'SSL',
|
||||||
|
`allowSelfSignedCerts` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`systemEmailAddress` VARCHAR(191) NULL,
|
||||||
|
`systemEmailPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`customerEmailLabel` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`isDefault` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `EmailProviderConfig_name_key`(`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `StressfreiEmail` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`email` VARCHAR(191) NOT NULL,
|
||||||
|
`platform` VARCHAR(191) NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`isProvisioned` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`provisionedAt` DATETIME(3) NULL,
|
||||||
|
`provisionError` TEXT NULL,
|
||||||
|
`hasMailbox` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`emailPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `CachedEmail` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`stressfreiEmailId` INTEGER NOT NULL,
|
||||||
|
`folder` ENUM('INBOX', 'SENT') NOT NULL DEFAULT 'INBOX',
|
||||||
|
`messageId` VARCHAR(191) NOT NULL,
|
||||||
|
`uid` INTEGER NOT NULL,
|
||||||
|
`subject` VARCHAR(191) NULL,
|
||||||
|
`fromAddress` VARCHAR(191) NOT NULL,
|
||||||
|
`fromName` VARCHAR(191) NULL,
|
||||||
|
`toAddresses` TEXT NOT NULL,
|
||||||
|
`ccAddresses` TEXT NULL,
|
||||||
|
`receivedAt` DATETIME(3) NOT NULL,
|
||||||
|
`textBody` LONGTEXT NULL,
|
||||||
|
`htmlBody` LONGTEXT NULL,
|
||||||
|
`hasAttachments` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`attachmentNames` TEXT NULL,
|
||||||
|
`contractId` INTEGER NULL,
|
||||||
|
`assignedAt` DATETIME(3) NULL,
|
||||||
|
`assignedBy` INTEGER NULL,
|
||||||
|
`isAutoAssigned` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`isRead` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`isStarred` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`isDeleted` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`deletedAt` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
INDEX `CachedEmail_contractId_idx`(`contractId`),
|
||||||
|
INDEX `CachedEmail_stressfreiEmailId_folder_receivedAt_idx`(`stressfreiEmailId`, `folder`, `receivedAt`),
|
||||||
|
INDEX `CachedEmail_stressfreiEmailId_isDeleted_idx`(`stressfreiEmailId`, `isDeleted`),
|
||||||
|
UNIQUE INDEX `CachedEmail_stressfreiEmailId_messageId_folder_key`(`stressfreiEmailId`, `messageId`, `folder`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Meter` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`meterNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`type` ENUM('ELECTRICITY', 'GAS') NOT NULL,
|
||||||
|
`tariffModel` ENUM('SINGLE', 'DUAL') NOT NULL DEFAULT 'SINGLE',
|
||||||
|
`location` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `MeterReading` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`meterId` INTEGER NOT NULL,
|
||||||
|
`readingDate` DATETIME(3) NOT NULL,
|
||||||
|
`value` DOUBLE NOT NULL,
|
||||||
|
`valueNt` DOUBLE NULL,
|
||||||
|
`unit` VARCHAR(191) NOT NULL DEFAULT 'kWh',
|
||||||
|
`notes` VARCHAR(191) NULL,
|
||||||
|
`reportedBy` VARCHAR(191) NULL,
|
||||||
|
`status` ENUM('RECORDED', 'REPORTED', 'TRANSFERRED') NOT NULL DEFAULT 'RECORDED',
|
||||||
|
`transferredAt` DATETIME(3) NULL,
|
||||||
|
`transferredBy` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `SalesPlatform` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`contactInfo` TEXT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `SalesPlatform_name_key`(`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `CancellationPeriod` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`code` VARCHAR(191) NOT NULL,
|
||||||
|
`description` VARCHAR(191) NOT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `CancellationPeriod_code_key`(`code`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractDuration` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`code` VARCHAR(191) NOT NULL,
|
||||||
|
`description` VARCHAR(191) NOT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `ContractDuration_code_key`(`code`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Provider` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`portalUrl` VARCHAR(191) NULL,
|
||||||
|
`usernameFieldName` VARCHAR(191) NULL,
|
||||||
|
`passwordFieldName` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Provider_name_key`(`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Tariff` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`providerId` INTEGER NOT NULL,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Tariff_providerId_name_key`(`providerId`, `name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractCategory` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`code` VARCHAR(191) NOT NULL,
|
||||||
|
`name` VARCHAR(191) NOT NULL,
|
||||||
|
`icon` VARCHAR(191) NULL,
|
||||||
|
`color` VARCHAR(191) NULL,
|
||||||
|
`sortOrder` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `ContractCategory_code_key`(`code`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Contract` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`type` ENUM('ELECTRICITY', 'GAS', 'DSL', 'CABLE', 'FIBER', 'MOBILE', 'TV', 'CAR_INSURANCE') NOT NULL,
|
||||||
|
`status` ENUM('DRAFT', 'PENDING', 'ACTIVE', 'CANCELLED', 'EXPIRED', 'DEACTIVATED') NOT NULL DEFAULT 'DRAFT',
|
||||||
|
`contractCategoryId` INTEGER NULL,
|
||||||
|
`addressId` INTEGER NULL,
|
||||||
|
`billingAddressId` INTEGER NULL,
|
||||||
|
`bankCardId` INTEGER NULL,
|
||||||
|
`identityDocumentId` INTEGER NULL,
|
||||||
|
`salesPlatformId` INTEGER NULL,
|
||||||
|
`cancellationPeriodId` INTEGER NULL,
|
||||||
|
`contractDurationId` INTEGER NULL,
|
||||||
|
`previousContractId` INTEGER NULL,
|
||||||
|
`previousProviderId` INTEGER NULL,
|
||||||
|
`previousCustomerNumber` VARCHAR(191) NULL,
|
||||||
|
`previousContractNumber` VARCHAR(191) NULL,
|
||||||
|
`providerId` INTEGER NULL,
|
||||||
|
`tariffId` INTEGER NULL,
|
||||||
|
`providerName` VARCHAR(191) NULL,
|
||||||
|
`tariffName` VARCHAR(191) NULL,
|
||||||
|
`customerNumberAtProvider` VARCHAR(191) NULL,
|
||||||
|
`contractNumberAtProvider` VARCHAR(191) NULL,
|
||||||
|
`priceFirst12Months` VARCHAR(191) NULL,
|
||||||
|
`priceFrom13Months` VARCHAR(191) NULL,
|
||||||
|
`priceAfter24Months` VARCHAR(191) NULL,
|
||||||
|
`startDate` DATETIME(3) NULL,
|
||||||
|
`endDate` DATETIME(3) NULL,
|
||||||
|
`commission` DOUBLE NULL,
|
||||||
|
`cancellationLetterPath` VARCHAR(191) NULL,
|
||||||
|
`cancellationConfirmationPath` VARCHAR(191) NULL,
|
||||||
|
`cancellationLetterOptionsPath` VARCHAR(191) NULL,
|
||||||
|
`cancellationConfirmationOptionsPath` VARCHAR(191) NULL,
|
||||||
|
`cancellationConfirmationDate` DATETIME(3) NULL,
|
||||||
|
`cancellationConfirmationOptionsDate` DATETIME(3) NULL,
|
||||||
|
`wasSpecialCancellation` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`portalUsername` VARCHAR(191) NULL,
|
||||||
|
`portalPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`stressfreiEmailId` INTEGER NULL,
|
||||||
|
`nextReviewDate` DATETIME(3) NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `Contract_contractNumber_key`(`contractNumber`),
|
||||||
|
UNIQUE INDEX `Contract_previousContractId_key`(`previousContractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractDocument` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`documentType` VARCHAR(191) NOT NULL,
|
||||||
|
`documentPath` VARCHAR(191) NOT NULL,
|
||||||
|
`originalName` VARCHAR(191) NOT NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`uploadedBy` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
INDEX `ContractDocument_contractId_idx`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractHistoryEntry` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`title` VARCHAR(191) NOT NULL,
|
||||||
|
`description` TEXT NULL,
|
||||||
|
`isAutomatic` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`createdBy` VARCHAR(191) NOT NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractTask` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`title` VARCHAR(191) NOT NULL,
|
||||||
|
`description` TEXT NULL,
|
||||||
|
`status` ENUM('OPEN', 'COMPLETED') NOT NULL DEFAULT 'OPEN',
|
||||||
|
`visibleInPortal` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`createdBy` VARCHAR(191) NULL,
|
||||||
|
`completedAt` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractTaskSubtask` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`taskId` INTEGER NOT NULL,
|
||||||
|
`title` VARCHAR(191) NOT NULL,
|
||||||
|
`status` ENUM('OPEN', 'COMPLETED') NOT NULL DEFAULT 'OPEN',
|
||||||
|
`createdBy` VARCHAR(191) NULL,
|
||||||
|
`completedAt` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `EnergyContractDetails` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`meterId` INTEGER NULL,
|
||||||
|
`maloId` VARCHAR(191) NULL,
|
||||||
|
`annualConsumption` DOUBLE NULL,
|
||||||
|
`annualConsumptionKwh` DOUBLE NULL,
|
||||||
|
`basePrice` DOUBLE NULL,
|
||||||
|
`unitPrice` DOUBLE NULL,
|
||||||
|
`unitPriceNt` DOUBLE NULL,
|
||||||
|
`bonus` DOUBLE NULL,
|
||||||
|
`previousProviderName` VARCHAR(191) NULL,
|
||||||
|
`previousCustomerNumber` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `EnergyContractDetails_contractId_key`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `ContractMeter` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`energyContractDetailsId` INTEGER NOT NULL,
|
||||||
|
`meterId` INTEGER NOT NULL,
|
||||||
|
`position` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`installedAt` DATETIME(3) NULL,
|
||||||
|
`removedAt` DATETIME(3) NULL,
|
||||||
|
`finalReading` DOUBLE NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
INDEX `ContractMeter_energyContractDetailsId_idx`(`energyContractDetailsId`),
|
||||||
|
UNIQUE INDEX `ContractMeter_energyContractDetailsId_meterId_key`(`energyContractDetailsId`, `meterId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `Invoice` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`energyContractDetailsId` INTEGER NULL,
|
||||||
|
`contractId` INTEGER NULL,
|
||||||
|
`invoiceDate` DATETIME(3) NOT NULL,
|
||||||
|
`invoiceType` ENUM('INTERIM', 'FINAL', 'NOT_AVAILABLE') NOT NULL,
|
||||||
|
`documentPath` VARCHAR(191) NULL,
|
||||||
|
`notes` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
INDEX `Invoice_energyContractDetailsId_idx`(`energyContractDetailsId`),
|
||||||
|
INDEX `Invoice_contractId_idx`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `InternetContractDetails` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`downloadSpeed` INTEGER NULL,
|
||||||
|
`uploadSpeed` INTEGER NULL,
|
||||||
|
`routerModel` VARCHAR(191) NULL,
|
||||||
|
`routerSerialNumber` VARCHAR(191) NULL,
|
||||||
|
`installationDate` DATETIME(3) NULL,
|
||||||
|
`internetUsername` VARCHAR(191) NULL,
|
||||||
|
`internetPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`propertyType` VARCHAR(191) NULL,
|
||||||
|
`propertyLocation` VARCHAR(191) NULL,
|
||||||
|
`connectionLocation` VARCHAR(191) NULL,
|
||||||
|
`homeId` VARCHAR(191) NULL,
|
||||||
|
`activationCode` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `InternetContractDetails_contractId_key`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `PhoneNumber` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`internetContractDetailsId` INTEGER NOT NULL,
|
||||||
|
`phoneNumber` VARCHAR(191) NOT NULL,
|
||||||
|
`isMain` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`sipUsername` VARCHAR(191) NULL,
|
||||||
|
`sipPasswordEncrypted` VARCHAR(191) NULL,
|
||||||
|
`sipServer` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `MobileContractDetails` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`requiresMultisim` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`dataVolume` DOUBLE NULL,
|
||||||
|
`includedMinutes` INTEGER NULL,
|
||||||
|
`includedSMS` INTEGER NULL,
|
||||||
|
`deviceModel` VARCHAR(191) NULL,
|
||||||
|
`deviceImei` VARCHAR(191) NULL,
|
||||||
|
`phoneNumber` VARCHAR(191) NULL,
|
||||||
|
`simCardNumber` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `MobileContractDetails_contractId_key`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `SimCard` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`mobileDetailsId` INTEGER NOT NULL,
|
||||||
|
`phoneNumber` VARCHAR(191) NULL,
|
||||||
|
`simCardNumber` VARCHAR(191) NULL,
|
||||||
|
`pin` VARCHAR(191) NULL,
|
||||||
|
`puk` VARCHAR(191) NULL,
|
||||||
|
`isMultisim` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`isMain` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `TvContractDetails` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`receiverModel` VARCHAR(191) NULL,
|
||||||
|
`smartcardNumber` VARCHAR(191) NULL,
|
||||||
|
`package` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `TvContractDetails_contractId_key`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `CarInsuranceDetails` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`contractId` INTEGER NOT NULL,
|
||||||
|
`licensePlate` VARCHAR(191) NULL,
|
||||||
|
`hsn` VARCHAR(191) NULL,
|
||||||
|
`tsn` VARCHAR(191) NULL,
|
||||||
|
`vin` VARCHAR(191) NULL,
|
||||||
|
`vehicleType` VARCHAR(191) NULL,
|
||||||
|
`firstRegistration` DATETIME(3) NULL,
|
||||||
|
`noClaimsClass` VARCHAR(191) NULL,
|
||||||
|
`insuranceType` ENUM('LIABILITY', 'PARTIAL', 'FULL') NOT NULL DEFAULT 'LIABILITY',
|
||||||
|
`deductiblePartial` DOUBLE NULL,
|
||||||
|
`deductibleFull` DOUBLE NULL,
|
||||||
|
`policyNumber` VARCHAR(191) NULL,
|
||||||
|
`previousInsurer` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `CarInsuranceDetails_contractId_key`(`contractId`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `AuditLog` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`userId` INTEGER NULL,
|
||||||
|
`userEmail` VARCHAR(191) NOT NULL,
|
||||||
|
`userRole` TEXT NULL,
|
||||||
|
`customerId` INTEGER NULL,
|
||||||
|
`isCustomerPortal` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`action` ENUM('CREATE', 'READ', 'UPDATE', 'DELETE', 'EXPORT', 'ANONYMIZE', 'LOGIN', 'LOGOUT', 'LOGIN_FAILED') NOT NULL,
|
||||||
|
`sensitivity` ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL') NOT NULL DEFAULT 'MEDIUM',
|
||||||
|
`resourceType` VARCHAR(191) NOT NULL,
|
||||||
|
`resourceId` VARCHAR(191) NULL,
|
||||||
|
`resourceLabel` VARCHAR(191) NULL,
|
||||||
|
`endpoint` VARCHAR(191) NOT NULL,
|
||||||
|
`httpMethod` VARCHAR(191) NOT NULL,
|
||||||
|
`ipAddress` VARCHAR(191) NOT NULL,
|
||||||
|
`userAgent` TEXT NULL,
|
||||||
|
`changesBefore` LONGTEXT NULL,
|
||||||
|
`changesAfter` LONGTEXT NULL,
|
||||||
|
`changesEncrypted` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`dataSubjectId` INTEGER NULL,
|
||||||
|
`legalBasis` VARCHAR(191) NULL,
|
||||||
|
`success` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`errorMessage` TEXT NULL,
|
||||||
|
`durationMs` INTEGER NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`hash` VARCHAR(191) NULL,
|
||||||
|
`previousHash` VARCHAR(191) NULL,
|
||||||
|
|
||||||
|
INDEX `AuditLog_userId_idx`(`userId`),
|
||||||
|
INDEX `AuditLog_customerId_idx`(`customerId`),
|
||||||
|
INDEX `AuditLog_resourceType_resourceId_idx`(`resourceType`, `resourceId`),
|
||||||
|
INDEX `AuditLog_dataSubjectId_idx`(`dataSubjectId`),
|
||||||
|
INDEX `AuditLog_action_idx`(`action`),
|
||||||
|
INDEX `AuditLog_createdAt_idx`(`createdAt`),
|
||||||
|
INDEX `AuditLog_sensitivity_idx`(`sensitivity`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `CustomerConsent` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`consentType` ENUM('DATA_PROCESSING', 'MARKETING_EMAIL', 'MARKETING_PHONE', 'DATA_SHARING_PARTNER') NOT NULL,
|
||||||
|
`status` ENUM('GRANTED', 'WITHDRAWN', 'PENDING') NOT NULL DEFAULT 'PENDING',
|
||||||
|
`grantedAt` DATETIME(3) NULL,
|
||||||
|
`withdrawnAt` DATETIME(3) NULL,
|
||||||
|
`source` VARCHAR(191) NULL,
|
||||||
|
`documentPath` VARCHAR(191) NULL,
|
||||||
|
`version` VARCHAR(191) NULL,
|
||||||
|
`ipAddress` VARCHAR(191) NULL,
|
||||||
|
`createdBy` VARCHAR(191) NOT NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
INDEX `CustomerConsent_customerId_idx`(`customerId`),
|
||||||
|
INDEX `CustomerConsent_consentType_idx`(`consentType`),
|
||||||
|
INDEX `CustomerConsent_status_idx`(`status`),
|
||||||
|
UNIQUE INDEX `CustomerConsent_customerId_consentType_key`(`customerId`, `consentType`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `DataDeletionRequest` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`customerId` INTEGER NOT NULL,
|
||||||
|
`status` ENUM('PENDING', 'IN_PROGRESS', 'COMPLETED', 'PARTIALLY_COMPLETED', 'REJECTED') NOT NULL DEFAULT 'PENDING',
|
||||||
|
`requestedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`requestSource` VARCHAR(191) NOT NULL,
|
||||||
|
`requestedBy` VARCHAR(191) NOT NULL,
|
||||||
|
`processedAt` DATETIME(3) NULL,
|
||||||
|
`processedBy` VARCHAR(191) NULL,
|
||||||
|
`deletedData` LONGTEXT NULL,
|
||||||
|
`retainedData` LONGTEXT NULL,
|
||||||
|
`retentionReason` TEXT NULL,
|
||||||
|
`proofDocument` VARCHAR(191) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
INDEX `DataDeletionRequest_customerId_idx`(`customerId`),
|
||||||
|
INDEX `DataDeletionRequest_status_idx`(`status`),
|
||||||
|
INDEX `DataDeletionRequest_requestedAt_idx`(`requestedAt`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `AuditRetentionPolicy` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`resourceType` VARCHAR(191) NOT NULL,
|
||||||
|
`sensitivity` ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL') NULL,
|
||||||
|
`retentionDays` INTEGER NOT NULL,
|
||||||
|
`description` VARCHAR(191) NULL,
|
||||||
|
`legalBasis` VARCHAR(191) NULL,
|
||||||
|
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `AuditRetentionPolicy_resourceType_sensitivity_key`(`resourceType`, `sensitivity`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `SecurityEvent` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`type` ENUM('LOGIN_FAILED', 'LOGIN_SUCCESS', 'RATE_LIMIT_HIT', 'ACCESS_DENIED', 'SSRF_BLOCKED', 'PASSWORD_RESET_REQUEST', 'PASSWORD_RESET_CONFIRM', 'LOGOUT', 'TOKEN_REJECTED', 'PERMISSION_CHANGED', 'SUSPICIOUS') NOT NULL,
|
||||||
|
`severity` ENUM('INFO', 'LOW', 'MEDIUM', 'HIGH', 'CRITICAL') NOT NULL,
|
||||||
|
`message` TEXT NOT NULL,
|
||||||
|
`ipAddress` VARCHAR(191) NULL,
|
||||||
|
`userId` INTEGER NULL,
|
||||||
|
`customerId` INTEGER NULL,
|
||||||
|
`userEmail` VARCHAR(191) NULL,
|
||||||
|
`endpoint` VARCHAR(191) NULL,
|
||||||
|
`details` JSON NULL,
|
||||||
|
`alerted` BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
`alertedAt` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
INDEX `SecurityEvent_type_createdAt_idx`(`type`, `createdAt`),
|
||||||
|
INDEX `SecurityEvent_severity_createdAt_idx`(`severity`, `createdAt`),
|
||||||
|
INDEX `SecurityEvent_ipAddress_createdAt_idx`(`ipAddress`, `createdAt`),
|
||||||
|
INDEX `SecurityEvent_alerted_severity_idx`(`alerted`, `severity`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `User` ADD CONSTRAINT `User_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `RolePermission` ADD CONSTRAINT `RolePermission_roleId_fkey` FOREIGN KEY (`roleId`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `RolePermission` ADD CONSTRAINT `RolePermission_permissionId_fkey` FOREIGN KEY (`permissionId`) REFERENCES `Permission`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `UserRole` ADD CONSTRAINT `UserRole_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `UserRole` ADD CONSTRAINT `UserRole_roleId_fkey` FOREIGN KEY (`roleId`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CustomerRepresentative` ADD CONSTRAINT `CustomerRepresentative_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CustomerRepresentative` ADD CONSTRAINT `CustomerRepresentative_representativeId_fkey` FOREIGN KEY (`representativeId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `RepresentativeAuthorization` ADD CONSTRAINT `RepresentativeAuthorization_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `RepresentativeAuthorization` ADD CONSTRAINT `RepresentativeAuthorization_representativeId_fkey` FOREIGN KEY (`representativeId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Address` ADD CONSTRAINT `Address_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `BankCard` ADD CONSTRAINT `BankCard_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `IdentityDocument` ADD CONSTRAINT `IdentityDocument_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `StressfreiEmail` ADD CONSTRAINT `StressfreiEmail_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CachedEmail` ADD CONSTRAINT `CachedEmail_stressfreiEmailId_fkey` FOREIGN KEY (`stressfreiEmailId`) REFERENCES `StressfreiEmail`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CachedEmail` ADD CONSTRAINT `CachedEmail_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Meter` ADD CONSTRAINT `Meter_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `MeterReading` ADD CONSTRAINT `MeterReading_meterId_fkey` FOREIGN KEY (`meterId`) REFERENCES `Meter`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Tariff` ADD CONSTRAINT `Tariff_providerId_fkey` FOREIGN KEY (`providerId`) REFERENCES `Provider`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_contractCategoryId_fkey` FOREIGN KEY (`contractCategoryId`) REFERENCES `ContractCategory`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_addressId_fkey` FOREIGN KEY (`addressId`) REFERENCES `Address`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_billingAddressId_fkey` FOREIGN KEY (`billingAddressId`) REFERENCES `Address`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_bankCardId_fkey` FOREIGN KEY (`bankCardId`) REFERENCES `BankCard`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_identityDocumentId_fkey` FOREIGN KEY (`identityDocumentId`) REFERENCES `IdentityDocument`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_salesPlatformId_fkey` FOREIGN KEY (`salesPlatformId`) REFERENCES `SalesPlatform`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_cancellationPeriodId_fkey` FOREIGN KEY (`cancellationPeriodId`) REFERENCES `CancellationPeriod`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_contractDurationId_fkey` FOREIGN KEY (`contractDurationId`) REFERENCES `ContractDuration`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_previousContractId_fkey` FOREIGN KEY (`previousContractId`) REFERENCES `Contract`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_previousProviderId_fkey` FOREIGN KEY (`previousProviderId`) REFERENCES `Provider`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_providerId_fkey` FOREIGN KEY (`providerId`) REFERENCES `Provider`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_tariffId_fkey` FOREIGN KEY (`tariffId`) REFERENCES `Tariff`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_stressfreiEmailId_fkey` FOREIGN KEY (`stressfreiEmailId`) REFERENCES `StressfreiEmail`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractDocument` ADD CONSTRAINT `ContractDocument_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractHistoryEntry` ADD CONSTRAINT `ContractHistoryEntry_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractTask` ADD CONSTRAINT `ContractTask_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractTaskSubtask` ADD CONSTRAINT `ContractTaskSubtask_taskId_fkey` FOREIGN KEY (`taskId`) REFERENCES `ContractTask`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `EnergyContractDetails` ADD CONSTRAINT `EnergyContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `EnergyContractDetails` ADD CONSTRAINT `EnergyContractDetails_meterId_fkey` FOREIGN KEY (`meterId`) REFERENCES `Meter`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractMeter` ADD CONSTRAINT `ContractMeter_energyContractDetailsId_fkey` FOREIGN KEY (`energyContractDetailsId`) REFERENCES `EnergyContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ContractMeter` ADD CONSTRAINT `ContractMeter_meterId_fkey` FOREIGN KEY (`meterId`) REFERENCES `Meter`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Invoice` ADD CONSTRAINT `Invoice_energyContractDetailsId_fkey` FOREIGN KEY (`energyContractDetailsId`) REFERENCES `EnergyContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `Invoice` ADD CONSTRAINT `Invoice_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `InternetContractDetails` ADD CONSTRAINT `InternetContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `PhoneNumber` ADD CONSTRAINT `PhoneNumber_internetContractDetailsId_fkey` FOREIGN KEY (`internetContractDetailsId`) REFERENCES `InternetContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `MobileContractDetails` ADD CONSTRAINT `MobileContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `SimCard` ADD CONSTRAINT `SimCard_mobileDetailsId_fkey` FOREIGN KEY (`mobileDetailsId`) REFERENCES `MobileContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `TvContractDetails` ADD CONSTRAINT `TvContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CarInsuranceDetails` ADD CONSTRAINT `CarInsuranceDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `CustomerConsent` ADD CONSTRAINT `CustomerConsent_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
@@ -1,354 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE `User` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`email` VARCHAR(191) NOT NULL,
|
|
||||||
`password` VARCHAR(191) NOT NULL,
|
|
||||||
`firstName` VARCHAR(191) NOT NULL,
|
|
||||||
`lastName` VARCHAR(191) NOT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`customerId` INTEGER NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `User_email_key`(`email`),
|
|
||||||
UNIQUE INDEX `User_customerId_key`(`customerId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Role` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`description` VARCHAR(191) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Role_name_key`(`name`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Permission` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`resource` VARCHAR(191) NOT NULL,
|
|
||||||
`action` VARCHAR(191) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Permission_resource_action_key`(`resource`, `action`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `RolePermission` (
|
|
||||||
`roleId` INTEGER NOT NULL,
|
|
||||||
`permissionId` INTEGER NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`roleId`, `permissionId`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `UserRole` (
|
|
||||||
`userId` INTEGER NOT NULL,
|
|
||||||
`roleId` INTEGER NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`userId`, `roleId`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Customer` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`type` ENUM('PRIVATE', 'BUSINESS') NOT NULL DEFAULT 'PRIVATE',
|
|
||||||
`salutation` VARCHAR(191) NULL,
|
|
||||||
`firstName` VARCHAR(191) NOT NULL,
|
|
||||||
`lastName` VARCHAR(191) NOT NULL,
|
|
||||||
`companyName` VARCHAR(191) NULL,
|
|
||||||
`email` VARCHAR(191) NULL,
|
|
||||||
`phone` VARCHAR(191) NULL,
|
|
||||||
`mobile` VARCHAR(191) NULL,
|
|
||||||
`taxNumber` VARCHAR(191) NULL,
|
|
||||||
`businessRegistration` TEXT NULL,
|
|
||||||
`commercialRegister` VARCHAR(191) NULL,
|
|
||||||
`notes` TEXT NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Customer_customerNumber_key`(`customerNumber`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Address` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`type` ENUM('DELIVERY_RESIDENCE', 'BILLING') NOT NULL DEFAULT 'DELIVERY_RESIDENCE',
|
|
||||||
`street` VARCHAR(191) NOT NULL,
|
|
||||||
`houseNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`postalCode` VARCHAR(191) NOT NULL,
|
|
||||||
`city` VARCHAR(191) NOT NULL,
|
|
||||||
`country` VARCHAR(191) NOT NULL DEFAULT 'Deutschland',
|
|
||||||
`isDefault` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `BankCard` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`accountHolder` VARCHAR(191) NOT NULL,
|
|
||||||
`iban` VARCHAR(191) NOT NULL,
|
|
||||||
`bic` VARCHAR(191) NULL,
|
|
||||||
`bankName` VARCHAR(191) NULL,
|
|
||||||
`expiryDate` DATETIME(3) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `IdentityDocument` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`type` ENUM('ID_CARD', 'PASSPORT', 'DRIVERS_LICENSE', 'OTHER') NOT NULL DEFAULT 'ID_CARD',
|
|
||||||
`documentNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`issuingAuthority` VARCHAR(191) NULL,
|
|
||||||
`issueDate` DATETIME(3) NULL,
|
|
||||||
`expiryDate` DATETIME(3) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Meter` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`meterNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`type` ENUM('ELECTRICITY', 'GAS') NOT NULL,
|
|
||||||
`location` VARCHAR(191) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `MeterReading` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`meterId` INTEGER NOT NULL,
|
|
||||||
`readingDate` DATETIME(3) NOT NULL,
|
|
||||||
`value` DOUBLE NOT NULL,
|
|
||||||
`unit` VARCHAR(191) NOT NULL DEFAULT 'kWh',
|
|
||||||
`notes` VARCHAR(191) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `SalesPlatform` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`contactInfo` TEXT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `SalesPlatform_name_key`(`name`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Contract` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`type` ENUM('ELECTRICITY', 'GAS', 'DSL', 'FIBER', 'MOBILE', 'TV', 'CAR_INSURANCE') NOT NULL,
|
|
||||||
`status` ENUM('DRAFT', 'PENDING', 'ACTIVE', 'CANCELLED', 'EXPIRED') NOT NULL DEFAULT 'DRAFT',
|
|
||||||
`addressId` INTEGER NULL,
|
|
||||||
`bankCardId` INTEGER NULL,
|
|
||||||
`identityDocumentId` INTEGER NULL,
|
|
||||||
`salesPlatformId` INTEGER NULL,
|
|
||||||
`previousContractId` INTEGER NULL,
|
|
||||||
`providerName` VARCHAR(191) NULL,
|
|
||||||
`tariffName` VARCHAR(191) NULL,
|
|
||||||
`customerNumberAtProvider` VARCHAR(191) NULL,
|
|
||||||
`startDate` DATETIME(3) NULL,
|
|
||||||
`endDate` DATETIME(3) NULL,
|
|
||||||
`cancellationPeriod` INTEGER NULL,
|
|
||||||
`commission` DOUBLE NULL,
|
|
||||||
`portalUsername` VARCHAR(191) NULL,
|
|
||||||
`portalPasswordEncrypted` VARCHAR(191) NULL,
|
|
||||||
`notes` TEXT NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Contract_contractNumber_key`(`contractNumber`),
|
|
||||||
UNIQUE INDEX `Contract_previousContractId_key`(`previousContractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `EnergyContractDetails` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`meterId` INTEGER NULL,
|
|
||||||
`annualConsumption` DOUBLE NULL,
|
|
||||||
`basePrice` DOUBLE NULL,
|
|
||||||
`unitPrice` DOUBLE NULL,
|
|
||||||
`bonus` DOUBLE NULL,
|
|
||||||
`previousProviderName` VARCHAR(191) NULL,
|
|
||||||
`previousCustomerNumber` VARCHAR(191) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `EnergyContractDetails_contractId_key`(`contractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `InternetContractDetails` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`downloadSpeed` INTEGER NULL,
|
|
||||||
`uploadSpeed` INTEGER NULL,
|
|
||||||
`routerModel` VARCHAR(191) NULL,
|
|
||||||
`routerSerialNumber` VARCHAR(191) NULL,
|
|
||||||
`installationDate` DATETIME(3) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `InternetContractDetails_contractId_key`(`contractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `PhoneNumber` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`internetContractDetailsId` INTEGER NOT NULL,
|
|
||||||
`phoneNumber` VARCHAR(191) NOT NULL,
|
|
||||||
`isMain` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `MobileContractDetails` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`phoneNumber` VARCHAR(191) NULL,
|
|
||||||
`simCardNumber` VARCHAR(191) NULL,
|
|
||||||
`dataVolume` DOUBLE NULL,
|
|
||||||
`includedMinutes` INTEGER NULL,
|
|
||||||
`includedSMS` INTEGER NULL,
|
|
||||||
`deviceModel` VARCHAR(191) NULL,
|
|
||||||
`deviceImei` VARCHAR(191) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `MobileContractDetails_contractId_key`(`contractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `TvContractDetails` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`receiverModel` VARCHAR(191) NULL,
|
|
||||||
`smartcardNumber` VARCHAR(191) NULL,
|
|
||||||
`package` VARCHAR(191) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `TvContractDetails_contractId_key`(`contractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `CarInsuranceDetails` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`licensePlate` VARCHAR(191) NULL,
|
|
||||||
`hsn` VARCHAR(191) NULL,
|
|
||||||
`tsn` VARCHAR(191) NULL,
|
|
||||||
`vin` VARCHAR(191) NULL,
|
|
||||||
`vehicleType` VARCHAR(191) NULL,
|
|
||||||
`firstRegistration` DATETIME(3) NULL,
|
|
||||||
`noClaimsClass` VARCHAR(191) NULL,
|
|
||||||
`insuranceType` ENUM('LIABILITY', 'PARTIAL', 'FULL') NOT NULL DEFAULT 'LIABILITY',
|
|
||||||
`deductiblePartial` DOUBLE NULL,
|
|
||||||
`deductibleFull` DOUBLE NULL,
|
|
||||||
`policyNumber` VARCHAR(191) NULL,
|
|
||||||
`previousInsurer` VARCHAR(191) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `CarInsuranceDetails_contractId_key`(`contractId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `User` ADD CONSTRAINT `User_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `RolePermission` ADD CONSTRAINT `RolePermission_roleId_fkey` FOREIGN KEY (`roleId`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `RolePermission` ADD CONSTRAINT `RolePermission_permissionId_fkey` FOREIGN KEY (`permissionId`) REFERENCES `Permission`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `UserRole` ADD CONSTRAINT `UserRole_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `UserRole` ADD CONSTRAINT `UserRole_roleId_fkey` FOREIGN KEY (`roleId`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Address` ADD CONSTRAINT `Address_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `BankCard` ADD CONSTRAINT `BankCard_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `IdentityDocument` ADD CONSTRAINT `IdentityDocument_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Meter` ADD CONSTRAINT `Meter_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `MeterReading` ADD CONSTRAINT `MeterReading_meterId_fkey` FOREIGN KEY (`meterId`) REFERENCES `Meter`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_addressId_fkey` FOREIGN KEY (`addressId`) REFERENCES `Address`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_bankCardId_fkey` FOREIGN KEY (`bankCardId`) REFERENCES `BankCard`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_identityDocumentId_fkey` FOREIGN KEY (`identityDocumentId`) REFERENCES `IdentityDocument`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_salesPlatformId_fkey` FOREIGN KEY (`salesPlatformId`) REFERENCES `SalesPlatform`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_previousContractId_fkey` FOREIGN KEY (`previousContractId`) REFERENCES `Contract`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `EnergyContractDetails` ADD CONSTRAINT `EnergyContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `EnergyContractDetails` ADD CONSTRAINT `EnergyContractDetails_meterId_fkey` FOREIGN KEY (`meterId`) REFERENCES `Meter`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `InternetContractDetails` ADD CONSTRAINT `InternetContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `PhoneNumber` ADD CONSTRAINT `PhoneNumber_internetContractDetailsId_fkey` FOREIGN KEY (`internetContractDetailsId`) REFERENCES `InternetContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `MobileContractDetails` ADD CONSTRAINT `MobileContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `TvContractDetails` ADD CONSTRAINT `TvContractDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CarInsuranceDetails` ADD CONSTRAINT `CarInsuranceDetails_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `BankCard` ADD COLUMN `documentPath` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `IdentityDocument` ADD COLUMN `documentPath` VARCHAR(191) NULL;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Customer` ADD COLUMN `birthDate` DATETIME(3) NULL,
|
|
||||||
ADD COLUMN `birthPlace` VARCHAR(191) NULL;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `IdentityDocument` ADD COLUMN `licenseClasses` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `licenseIssueDate` DATETIME(3) NULL;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- You are about to drop the column `businessRegistration` on the `Customer` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the column `commercialRegister` on the `Customer` table. All the data in the column will be lost.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Customer` DROP COLUMN `businessRegistration`,
|
|
||||||
DROP COLUMN `commercialRegister`,
|
|
||||||
ADD COLUMN `businessRegistrationPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `commercialRegisterNumber` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `commercialRegisterPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `foundingDate` DATETIME(3) NULL;
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- You are about to drop the column `cancellationPeriod` on the `Contract` table. All the data in the column will be lost.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` DROP COLUMN `cancellationPeriod`,
|
|
||||||
ADD COLUMN `cancellationPeriodId` INTEGER NULL,
|
|
||||||
ADD COLUMN `priceAfter24Months` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `priceFirst12Months` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `priceFrom13Months` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Customer` ADD COLUMN `privacyPolicyPath` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `CancellationPeriod` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`code` VARCHAR(191) NOT NULL,
|
|
||||||
`description` VARCHAR(191) NOT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `CancellationPeriod_code_key`(`code`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_cancellationPeriodId_fkey` FOREIGN KEY (`cancellationPeriodId`) REFERENCES `CancellationPeriod`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `contractDurationId` INTEGER NULL;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `ContractDuration` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`code` VARCHAR(191) NOT NULL,
|
|
||||||
`description` VARCHAR(191) NOT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `ContractDuration_code_key`(`code`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_contractDurationId_fkey` FOREIGN KEY (`contractDurationId`) REFERENCES `ContractDuration`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `cancellationConfirmationDate` DATETIME(3) NULL,
|
|
||||||
ADD COLUMN `cancellationConfirmationOptionsDate` DATETIME(3) NULL,
|
|
||||||
ADD COLUMN `cancellationConfirmationOptionsPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `cancellationConfirmationPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `cancellationLetterOptionsPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `cancellationLetterPath` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `wasSpecialCancellation` BOOLEAN NOT NULL DEFAULT false;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `providerId` INTEGER NULL,
|
|
||||||
ADD COLUMN `tariffId` INTEGER NULL;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Provider` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`portalUrl` VARCHAR(191) NULL,
|
|
||||||
`usernameFieldName` VARCHAR(191) NULL,
|
|
||||||
`passwordFieldName` VARCHAR(191) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Provider_name_key`(`name`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Tariff` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`providerId` INTEGER NOT NULL,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `Tariff_providerId_name_key`(`providerId`, `name`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Tariff` ADD CONSTRAINT `Tariff_providerId_fkey` FOREIGN KEY (`providerId`) REFERENCES `Provider`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_providerId_fkey` FOREIGN KEY (`providerId`) REFERENCES `Provider`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_tariffId_fkey` FOREIGN KEY (`tariffId`) REFERENCES `Tariff`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `MobileContractDetails` ADD COLUMN `requiresMultisim` BOOLEAN NOT NULL DEFAULT false;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `SimCard` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`mobileDetailsId` INTEGER NOT NULL,
|
|
||||||
`phoneNumber` VARCHAR(191) NULL,
|
|
||||||
`simCardNumber` VARCHAR(191) NULL,
|
|
||||||
`pin` VARCHAR(191) NULL,
|
|
||||||
`puk` VARCHAR(191) NULL,
|
|
||||||
`isMultisim` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`isMain` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `SimCard` ADD CONSTRAINT `SimCard_mobileDetailsId_fkey` FOREIGN KEY (`mobileDetailsId`) REFERENCES `MobileContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `contractCategoryId` INTEGER NULL;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `ContractCategory` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`code` VARCHAR(191) NOT NULL,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`icon` VARCHAR(191) NULL,
|
|
||||||
`color` VARCHAR(191) NULL,
|
|
||||||
`sortOrder` INTEGER NOT NULL DEFAULT 0,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `ContractCategory_code_key`(`code`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_contractCategoryId_fkey` FOREIGN KEY (`contractCategoryId`) REFERENCES `ContractCategory`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` MODIFY `type` ENUM('ELECTRICITY', 'GAS', 'DSL', 'CABLE', 'FIBER', 'MOBILE', 'TV', 'CAR_INSURANCE') NOT NULL;
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `InternetContractDetails` ADD COLUMN `activationCode` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `homeId` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `internetPasswordEncrypted` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `internetUsername` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `PhoneNumber` ADD COLUMN `sipPasswordEncrypted` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `sipServer` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `sipUsername` VARCHAR(191) NULL;
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- A unique constraint covering the columns `[portalEmail]` on the table `Customer` will be added. If there are existing duplicate values, this will fail.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `stressfreiEmailId` INTEGER NULL,
|
|
||||||
MODIFY `status` ENUM('DRAFT', 'PENDING', 'ACTIVE', 'CANCELLED', 'EXPIRED', 'DEACTIVATED') NOT NULL DEFAULT 'DRAFT';
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Customer` ADD COLUMN `portalEmail` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `portalEnabled` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
ADD COLUMN `portalLastLogin` DATETIME(3) NULL,
|
|
||||||
ADD COLUMN `portalPasswordEncrypted` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `portalPasswordHash` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `AppSetting` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`key` VARCHAR(191) NOT NULL,
|
|
||||||
`value` TEXT NOT NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `AppSetting_key_key`(`key`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `CustomerRepresentative` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`representativeId` INTEGER NOT NULL,
|
|
||||||
`notes` VARCHAR(191) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `CustomerRepresentative_customerId_representativeId_key`(`customerId`, `representativeId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `EmailProviderConfig` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` VARCHAR(191) NOT NULL,
|
|
||||||
`type` ENUM('PLESK', 'CPANEL', 'DIRECTADMIN') NOT NULL,
|
|
||||||
`apiUrl` VARCHAR(191) NOT NULL,
|
|
||||||
`apiKey` VARCHAR(191) NULL,
|
|
||||||
`username` VARCHAR(191) NULL,
|
|
||||||
`passwordEncrypted` VARCHAR(191) NULL,
|
|
||||||
`domain` VARCHAR(191) NOT NULL,
|
|
||||||
`defaultForwardEmail` VARCHAR(191) NULL,
|
|
||||||
`imapServer` VARCHAR(191) NULL,
|
|
||||||
`imapPort` INTEGER NULL DEFAULT 993,
|
|
||||||
`smtpServer` VARCHAR(191) NULL,
|
|
||||||
`smtpPort` INTEGER NULL DEFAULT 465,
|
|
||||||
`imapEncryption` ENUM('SSL', 'STARTTLS', 'NONE') NOT NULL DEFAULT 'SSL',
|
|
||||||
`smtpEncryption` ENUM('SSL', 'STARTTLS', 'NONE') NOT NULL DEFAULT 'SSL',
|
|
||||||
`allowSelfSignedCerts` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`isDefault` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `EmailProviderConfig_name_key`(`name`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `StressfreiEmail` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`email` VARCHAR(191) NOT NULL,
|
|
||||||
`platform` VARCHAR(191) NULL,
|
|
||||||
`notes` TEXT NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`isProvisioned` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`provisionedAt` DATETIME(3) NULL,
|
|
||||||
`provisionError` TEXT NULL,
|
|
||||||
`hasMailbox` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`emailPasswordEncrypted` VARCHAR(191) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `CachedEmail` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`stressfreiEmailId` INTEGER NOT NULL,
|
|
||||||
`folder` ENUM('INBOX', 'SENT') NOT NULL DEFAULT 'INBOX',
|
|
||||||
`messageId` VARCHAR(191) NOT NULL,
|
|
||||||
`uid` INTEGER NOT NULL,
|
|
||||||
`subject` VARCHAR(191) NULL,
|
|
||||||
`fromAddress` VARCHAR(191) NOT NULL,
|
|
||||||
`fromName` VARCHAR(191) NULL,
|
|
||||||
`toAddresses` TEXT NOT NULL,
|
|
||||||
`ccAddresses` TEXT NULL,
|
|
||||||
`receivedAt` DATETIME(3) NOT NULL,
|
|
||||||
`textBody` LONGTEXT NULL,
|
|
||||||
`htmlBody` LONGTEXT NULL,
|
|
||||||
`hasAttachments` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`attachmentNames` TEXT NULL,
|
|
||||||
`contractId` INTEGER NULL,
|
|
||||||
`assignedAt` DATETIME(3) NULL,
|
|
||||||
`assignedBy` INTEGER NULL,
|
|
||||||
`isAutoAssigned` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`isRead` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`isStarred` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`isDeleted` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`deletedAt` DATETIME(3) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
INDEX `CachedEmail_contractId_idx`(`contractId`),
|
|
||||||
INDEX `CachedEmail_stressfreiEmailId_folder_receivedAt_idx`(`stressfreiEmailId`, `folder`, `receivedAt`),
|
|
||||||
INDEX `CachedEmail_stressfreiEmailId_isDeleted_idx`(`stressfreiEmailId`, `isDeleted`),
|
|
||||||
UNIQUE INDEX `CachedEmail_stressfreiEmailId_messageId_folder_key`(`stressfreiEmailId`, `messageId`, `folder`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `ContractTask` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`title` VARCHAR(191) NOT NULL,
|
|
||||||
`description` TEXT NULL,
|
|
||||||
`status` ENUM('OPEN', 'COMPLETED') NOT NULL DEFAULT 'OPEN',
|
|
||||||
`visibleInPortal` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`createdBy` VARCHAR(191) NULL,
|
|
||||||
`completedAt` DATETIME(3) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `ContractTaskSubtask` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`taskId` INTEGER NOT NULL,
|
|
||||||
`title` VARCHAR(191) NOT NULL,
|
|
||||||
`status` ENUM('OPEN', 'COMPLETED') NOT NULL DEFAULT 'OPEN',
|
|
||||||
`createdBy` VARCHAR(191) NULL,
|
|
||||||
`completedAt` DATETIME(3) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX `Customer_portalEmail_key` ON `Customer`(`portalEmail`);
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CustomerRepresentative` ADD CONSTRAINT `CustomerRepresentative_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CustomerRepresentative` ADD CONSTRAINT `CustomerRepresentative_representativeId_fkey` FOREIGN KEY (`representativeId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `StressfreiEmail` ADD CONSTRAINT `StressfreiEmail_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CachedEmail` ADD CONSTRAINT `CachedEmail_stressfreiEmailId_fkey` FOREIGN KEY (`stressfreiEmailId`) REFERENCES `StressfreiEmail`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CachedEmail` ADD CONSTRAINT `CachedEmail_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_stressfreiEmailId_fkey` FOREIGN KEY (`stressfreiEmailId`) REFERENCES `StressfreiEmail`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `ContractTask` ADD CONSTRAINT `ContractTask_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `ContractTaskSubtask` ADD CONSTRAINT `ContractTaskSubtask_taskId_fkey` FOREIGN KEY (`taskId`) REFERENCES `ContractTask`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `User` ADD COLUMN `tokenInvalidatedAt` DATETIME(3) NULL;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `billingAddressId` INTEGER NULL;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_billingAddressId_fkey` FOREIGN KEY (`billingAddressId`) REFERENCES `Address`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `EnergyContractDetails` ADD COLUMN `annualConsumptionKwh` DOUBLE NULL;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `EnergyContractDetails` ADD COLUMN `maloId` VARCHAR(191) NULL;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE `Invoice` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`energyContractDetailsId` INTEGER NOT NULL,
|
|
||||||
`invoiceDate` DATETIME(3) NOT NULL,
|
|
||||||
`invoiceType` ENUM('INTERIM', 'FINAL', 'NOT_AVAILABLE') NOT NULL,
|
|
||||||
`documentPath` VARCHAR(191) NULL,
|
|
||||||
`notes` VARCHAR(191) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
INDEX `Invoice_energyContractDetailsId_idx`(`energyContractDetailsId`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Invoice` ADD CONSTRAINT `Invoice_energyContractDetailsId_fkey` FOREIGN KEY (`energyContractDetailsId`) REFERENCES `EnergyContractDetails`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `nextReviewDate` DATETIME(3) NULL;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `contractNumberAtProvider` VARCHAR(191) NULL;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Contract` ADD COLUMN `previousContractNumber` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `previousCustomerNumber` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `previousProviderId` INTEGER NULL;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `Contract` ADD CONSTRAINT `Contract_previousProviderId_fkey` FOREIGN KEY (`previousProviderId`) REFERENCES `Provider`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE `ContractHistoryEntry` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`contractId` INTEGER NOT NULL,
|
|
||||||
`title` VARCHAR(191) NOT NULL,
|
|
||||||
`description` TEXT NULL,
|
|
||||||
`isAutomatic` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`createdBy` VARCHAR(191) NOT NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `ContractHistoryEntry` ADD CONSTRAINT `ContractHistoryEntry_contractId_fkey` FOREIGN KEY (`contractId`) REFERENCES `Contract`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE `AuditLog` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`userId` INTEGER NULL,
|
|
||||||
`userEmail` VARCHAR(191) NOT NULL,
|
|
||||||
`userRole` VARCHAR(191) NULL,
|
|
||||||
`customerId` INTEGER NULL,
|
|
||||||
`isCustomerPortal` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`action` ENUM('CREATE', 'READ', 'UPDATE', 'DELETE', 'EXPORT', 'ANONYMIZE', 'LOGIN', 'LOGOUT', 'LOGIN_FAILED') NOT NULL,
|
|
||||||
`sensitivity` ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL') NOT NULL DEFAULT 'MEDIUM',
|
|
||||||
`resourceType` VARCHAR(191) NOT NULL,
|
|
||||||
`resourceId` VARCHAR(191) NULL,
|
|
||||||
`resourceLabel` VARCHAR(191) NULL,
|
|
||||||
`endpoint` VARCHAR(191) NOT NULL,
|
|
||||||
`httpMethod` VARCHAR(191) NOT NULL,
|
|
||||||
`ipAddress` VARCHAR(191) NOT NULL,
|
|
||||||
`userAgent` TEXT NULL,
|
|
||||||
`changesBefore` LONGTEXT NULL,
|
|
||||||
`changesAfter` LONGTEXT NULL,
|
|
||||||
`changesEncrypted` BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
`dataSubjectId` INTEGER NULL,
|
|
||||||
`legalBasis` VARCHAR(191) NULL,
|
|
||||||
`success` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`errorMessage` TEXT NULL,
|
|
||||||
`durationMs` INTEGER NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`hash` VARCHAR(191) NULL,
|
|
||||||
`previousHash` VARCHAR(191) NULL,
|
|
||||||
|
|
||||||
INDEX `AuditLog_userId_idx`(`userId`),
|
|
||||||
INDEX `AuditLog_customerId_idx`(`customerId`),
|
|
||||||
INDEX `AuditLog_resourceType_resourceId_idx`(`resourceType`, `resourceId`),
|
|
||||||
INDEX `AuditLog_dataSubjectId_idx`(`dataSubjectId`),
|
|
||||||
INDEX `AuditLog_action_idx`(`action`),
|
|
||||||
INDEX `AuditLog_createdAt_idx`(`createdAt`),
|
|
||||||
INDEX `AuditLog_sensitivity_idx`(`sensitivity`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `CustomerConsent` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`consentType` ENUM('DATA_PROCESSING', 'MARKETING_EMAIL', 'MARKETING_PHONE', 'DATA_SHARING_PARTNER') NOT NULL,
|
|
||||||
`status` ENUM('GRANTED', 'WITHDRAWN', 'PENDING') NOT NULL DEFAULT 'PENDING',
|
|
||||||
`grantedAt` DATETIME(3) NULL,
|
|
||||||
`withdrawnAt` DATETIME(3) NULL,
|
|
||||||
`source` VARCHAR(191) NULL,
|
|
||||||
`documentPath` VARCHAR(191) NULL,
|
|
||||||
`version` VARCHAR(191) NULL,
|
|
||||||
`ipAddress` VARCHAR(191) NULL,
|
|
||||||
`createdBy` VARCHAR(191) NOT NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
INDEX `CustomerConsent_customerId_idx`(`customerId`),
|
|
||||||
INDEX `CustomerConsent_consentType_idx`(`consentType`),
|
|
||||||
INDEX `CustomerConsent_status_idx`(`status`),
|
|
||||||
UNIQUE INDEX `CustomerConsent_customerId_consentType_key`(`customerId`, `consentType`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `DataDeletionRequest` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`customerId` INTEGER NOT NULL,
|
|
||||||
`status` ENUM('PENDING', 'IN_PROGRESS', 'COMPLETED', 'PARTIALLY_COMPLETED', 'REJECTED') NOT NULL DEFAULT 'PENDING',
|
|
||||||
`requestedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`requestSource` VARCHAR(191) NOT NULL,
|
|
||||||
`requestedBy` VARCHAR(191) NOT NULL,
|
|
||||||
`processedAt` DATETIME(3) NULL,
|
|
||||||
`processedBy` VARCHAR(191) NULL,
|
|
||||||
`deletedData` LONGTEXT NULL,
|
|
||||||
`retainedData` LONGTEXT NULL,
|
|
||||||
`retentionReason` TEXT NULL,
|
|
||||||
`proofDocument` VARCHAR(191) NULL,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
INDEX `DataDeletionRequest_customerId_idx`(`customerId`),
|
|
||||||
INDEX `DataDeletionRequest_status_idx`(`status`),
|
|
||||||
INDEX `DataDeletionRequest_requestedAt_idx`(`requestedAt`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE `AuditRetentionPolicy` (
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`resourceType` VARCHAR(191) NOT NULL,
|
|
||||||
`sensitivity` ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL') NULL,
|
|
||||||
`retentionDays` INTEGER NOT NULL,
|
|
||||||
`description` VARCHAR(191) NULL,
|
|
||||||
`legalBasis` VARCHAR(191) NULL,
|
|
||||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
||||||
`updatedAt` DATETIME(3) NOT NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `AuditRetentionPolicy_resourceType_sensitivity_key`(`resourceType`, `sensitivity`),
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE `CustomerConsent` ADD CONSTRAINT `CustomerConsent_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE `Customer` ADD COLUMN `consentHash` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE `User` ADD COLUMN `whatsappNumber` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `telegramUsername` VARCHAR(191) NULL,
|
|
||||||
ADD COLUMN `signalNumber` VARCHAR(191) NULL;
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX `Customer_consentHash_key` ON `Customer`(`consentHash`);
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# Please do not edit this file manually
|
# Please do not edit this file manually
|
||||||
# It should be added in your version-control system (i.e. Git)
|
# It should be added in your version-control system (i.e. Git)
|
||||||
provider = "mysql"
|
provider = "mysql"
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ import { PrismaClient } from '@prisma/client';
|
|||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const ROOT = path.join(process.cwd(), 'factory-defaults');
|
// ROOT kann via FACTORY_DEFAULTS_DIR überschrieben werden (Container-Bootstrap
|
||||||
|
// mit eingebauten Defaults aus dem Image).
|
||||||
|
const ROOT = process.env.FACTORY_DEFAULTS_DIR
|
||||||
|
? path.resolve(process.env.FACTORY_DEFAULTS_DIR)
|
||||||
|
: path.join(process.cwd(), 'factory-defaults');
|
||||||
const UPLOADS_ROOT = path.join(process.cwd(), 'uploads');
|
const UPLOADS_ROOT = path.join(process.cwd(), 'uploads');
|
||||||
const PDF_UPLOAD_DIR = path.join(UPLOADS_ROOT, 'pdf-templates');
|
const PDF_UPLOAD_DIR = path.join(UPLOADS_ROOT, 'pdf-templates');
|
||||||
|
|
||||||
@@ -61,6 +65,19 @@ interface PdfTemplateDef {
|
|||||||
pdfFilename: string; // Dateiname im pdf-templates/-Ordner
|
pdfFilename: string; // Dateiname im pdf-templates/-Ordner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AppSettingDef {
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whitelist – muss synchron zu factoryDefaults.service.ts sein.
|
||||||
|
const FACTORY_DEFAULT_APP_SETTING_KEYS = new Set([
|
||||||
|
'privacyPolicyHtml',
|
||||||
|
'authorizationTemplateHtml',
|
||||||
|
'imprintHtml',
|
||||||
|
'websitePrivacyPolicyHtml',
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Liest alle *.json Dateien aus einem Ordner und gibt die zusammengeführten Arrays zurück.
|
* Liest alle *.json Dateien aus einem Ordner und gibt die zusammengeführten Arrays zurück.
|
||||||
*/
|
*/
|
||||||
@@ -299,6 +316,31 @@ async function seedPdfTemplates() {
|
|||||||
console.log(` ✓ PDF-Vorlagen: ${count}${skipped > 0 ? ` (${skipped} übersprungen)` : ''}`);
|
console.log(` ✓ PDF-Vorlagen: ${count}${skipped > 0 ? ` (${skipped} übersprungen)` : ''}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function seedAppSettings() {
|
||||||
|
const items = readJsonArrays<AppSettingDef>(path.join(ROOT, 'app-settings'));
|
||||||
|
if (items.length === 0) {
|
||||||
|
console.log(' app-settings – keine Einträge');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let count = 0;
|
||||||
|
let skipped = 0;
|
||||||
|
for (const s of items) {
|
||||||
|
if (!s.key || typeof s.value !== 'string') continue;
|
||||||
|
if (!FACTORY_DEFAULT_APP_SETTING_KEYS.has(s.key)) {
|
||||||
|
console.warn(` ⚠ AppSetting-Key '${s.key}' nicht auf Whitelist – übersprungen`);
|
||||||
|
skipped++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await prisma.appSetting.upsert({
|
||||||
|
where: { key: s.key },
|
||||||
|
update: { value: s.value },
|
||||||
|
create: { key: s.key, value: s.value },
|
||||||
|
});
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
console.log(` ✓ HTML-Templates: ${count}${skipped > 0 ? ` (${skipped} übersprungen)` : ''}`);
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('\n📦 Factory-Defaults werden eingespielt...\n');
|
console.log('\n📦 Factory-Defaults werden eingespielt...\n');
|
||||||
|
|
||||||
@@ -313,6 +355,7 @@ async function main() {
|
|||||||
await seedContractDurations();
|
await seedContractDurations();
|
||||||
await seedContractCategories();
|
await seedContractCategories();
|
||||||
await seedPdfTemplates();
|
await seedPdfTemplates();
|
||||||
|
await seedAppSettings();
|
||||||
|
|
||||||
console.log('\n✅ Factory-Defaults erfolgreich eingespielt.\n');
|
console.log('\n✅ Factory-Defaults erfolgreich eingespielt.\n');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,6 +256,58 @@ export async function createFollowUp(req: AuthRequest, res: Response): Promise<v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VVL = Vertragsverlängerung beim selben Anbieter.
|
||||||
|
* Erstellt einen neuen Vertrag mit allen Daten des Vorgängers (außer
|
||||||
|
* Auftragsdokument), Startdatum = altes Start + Vertragslaufzeit.
|
||||||
|
*/
|
||||||
|
export async function createRenewal(req: AuthRequest, res: Response): Promise<void> {
|
||||||
|
try {
|
||||||
|
const previousContractId = parseInt(req.params.id);
|
||||||
|
|
||||||
|
const previousContract = await prisma.contract.findUnique({
|
||||||
|
where: { id: previousContractId },
|
||||||
|
select: { contractNumber: true },
|
||||||
|
});
|
||||||
|
if (!previousContract) {
|
||||||
|
res.status(404).json({ success: false, error: 'Vorgängervertrag nicht gefunden' } as ApiResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contract = await contractService.createRenewalContract(previousContractId);
|
||||||
|
if (!contract) {
|
||||||
|
res.status(500).json({ success: false, error: 'VVL konnte nicht erstellt werden' } as ApiResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const createdBy = req.user?.email || 'unbekannt';
|
||||||
|
|
||||||
|
await contractHistoryService.createRenewalHistoryEntry(
|
||||||
|
previousContractId,
|
||||||
|
contract.contractNumber,
|
||||||
|
createdBy,
|
||||||
|
);
|
||||||
|
await contractHistoryService.createNewRenewalFromPredecessorEntry(
|
||||||
|
contract.id,
|
||||||
|
previousContract.contractNumber,
|
||||||
|
createdBy,
|
||||||
|
);
|
||||||
|
|
||||||
|
await logChange({
|
||||||
|
req, action: 'CREATE', resourceType: 'Contract',
|
||||||
|
resourceId: contract.id.toString(),
|
||||||
|
label: `VVL erstellt für ${previousContract.contractNumber}`,
|
||||||
|
customerId: contract.customerId,
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(201).json({ success: true, data: contract } as ApiResponse);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : 'Fehler beim Erstellen der VVL',
|
||||||
|
} as ApiResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getContractPassword(req: AuthRequest, res: Response): Promise<void> {
|
export async function getContractPassword(req: AuthRequest, res: Response): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const contractId = parseInt(req.params.id);
|
const contractId = parseInt(req.params.id);
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export async function previewFactoryDefaults(req: AuthRequest, res: Response) {
|
|||||||
contractDurations: data.contractDurations.length,
|
contractDurations: data.contractDurations.length,
|
||||||
contractCategories: data.contractCategories.length,
|
contractCategories: data.contractCategories.length,
|
||||||
pdfTemplates: data.pdfTemplates.length,
|
pdfTemplates: data.pdfTemplates.length,
|
||||||
|
appSettings: data.appSettings.length,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -62,3 +63,39 @@ export async function previewFactoryDefaults(req: AuthRequest, res: Response) {
|
|||||||
res.status(500).json({ success: false, error: 'Fehler beim Laden' });
|
res.status(500).json({ success: false, error: 'Fehler beim Laden' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory-Defaults aus ZIP importieren (Upload via multipart/form-data, Feld 'zip').
|
||||||
|
* Idempotent: bestehende Einträge werden per unique-Key aktualisiert, nichts wird gelöscht.
|
||||||
|
*/
|
||||||
|
export async function importFactoryDefaults(req: AuthRequest, res: Response) {
|
||||||
|
try {
|
||||||
|
const file = (req as any).file as Express.Multer.File | undefined;
|
||||||
|
if (!file || !file.buffer) {
|
||||||
|
return res.status(400).json({ success: false, error: 'Keine ZIP-Datei hochgeladen' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await factoryDefaultsService.importFactoryDefaults(file.buffer);
|
||||||
|
|
||||||
|
await createAuditLog({
|
||||||
|
userId: req.user?.userId,
|
||||||
|
userEmail: req.user?.email || 'unknown',
|
||||||
|
// 'UPDATE' weil Factory-Defaults DB-Records upserted; das Label nennt
|
||||||
|
// den Vorgang explizit als Import.
|
||||||
|
action: 'UPDATE',
|
||||||
|
resourceType: 'FactoryDefaults',
|
||||||
|
resourceLabel: `Factory-Defaults importiert: ${result.providers} Anbieter, ${result.tariffs} Tarife, ${result.pdfTemplates} PDF-Vorlagen, ${result.appSettings} HTML-Templates`,
|
||||||
|
endpoint: req.path,
|
||||||
|
httpMethod: req.method,
|
||||||
|
ipAddress: req.socket.remoteAddress || 'unknown',
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json({ success: true, data: result });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler beim Factory-Defaults-Import:', error);
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : 'Fehler beim Import',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,8 +72,19 @@ export async function updateUser(req: Request, res: Response): Promise<void> {
|
|||||||
// Whitelist: nur erlaubte Felder aus req.body übernehmen (Mass-Assignment-Schutz)
|
// Whitelist: nur erlaubte Felder aus req.body übernehmen (Mass-Assignment-Schutz)
|
||||||
const data = pickUserUpdate(req.body);
|
const data = pickUserUpdate(req.body);
|
||||||
|
|
||||||
// Vorherigen Stand laden für Audit
|
// Vorherigen Stand laden für Audit – inkl. Rollen, damit hasGdprAccess /
|
||||||
const before = await prisma.user.findUnique({ where: { id: userId } });
|
// hasDeveloperAccess (versteckte Rollen) korrekt verglichen werden.
|
||||||
|
const beforeUser = await prisma.user.findUnique({
|
||||||
|
where: { id: userId },
|
||||||
|
include: { roles: { include: { role: true } } },
|
||||||
|
});
|
||||||
|
const before = beforeUser
|
||||||
|
? {
|
||||||
|
...beforeUser,
|
||||||
|
hasGdprAccess: beforeUser.roles.some((ur) => ur.role.name === 'DSGVO'),
|
||||||
|
hasDeveloperAccess: beforeUser.roles.some((ur) => ur.role.name === 'Developer'),
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
const user = await userService.updateUser(userId, data as any);
|
const user = await userService.updateUser(userId, data as any);
|
||||||
if (user) {
|
if (user) {
|
||||||
@@ -82,6 +93,7 @@ export async function updateUser(req: Request, res: Response): Promise<void> {
|
|||||||
const changes: Record<string, { von: unknown; nach: unknown }> = {};
|
const changes: Record<string, { von: unknown; nach: unknown }> = {};
|
||||||
const fieldLabels: Record<string, string> = {
|
const fieldLabels: Record<string, string> = {
|
||||||
email: 'E-Mail', firstName: 'Vorname', lastName: 'Nachname', isActive: 'Aktiv',
|
email: 'E-Mail', firstName: 'Vorname', lastName: 'Nachname', isActive: 'Aktiv',
|
||||||
|
hasGdprAccess: 'DSGVO-Zugriff', hasDeveloperAccess: 'Entwicklerzugriff',
|
||||||
};
|
};
|
||||||
for (const [key, newVal] of Object.entries(data)) {
|
for (const [key, newVal] of Object.entries(data)) {
|
||||||
if (['id', 'createdAt', 'updatedAt'].includes(key)) continue;
|
if (['id', 'createdAt', 'updatedAt'].includes(key)) continue;
|
||||||
|
|||||||
+154
-8
@@ -3,6 +3,31 @@ import cors from 'cors';
|
|||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import dotenvExpand from 'dotenv-expand';
|
||||||
|
|
||||||
|
// .env-Dateien laden – Root-.env hat Priorität (zentrale Konfiguration für
|
||||||
|
// Dev + Docker), backend/.env als Legacy-Fallback. Im Container sind
|
||||||
|
// Variablen schon via env_file/environment gesetzt – dotenv überschreibt
|
||||||
|
// existierende process.env-Werte nicht.
|
||||||
|
// __dirname zeigt auf src/ (dev via tsx) oder dist/ (build). In beiden Fällen
|
||||||
|
// liegt Root /.env zwei Ebenen darüber.
|
||||||
|
//
|
||||||
|
// dotenvExpand löst ${VAR}-Substitution auf, sodass z.B.
|
||||||
|
// DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||||
|
// dynamisch aus den Komponenten zusammengebaut wird (kein Doppel-Pflegen).
|
||||||
|
dotenvExpand.expand(dotenv.config({ path: path.resolve(__dirname, '../../.env') }));
|
||||||
|
dotenvExpand.expand(dotenv.config({ path: path.resolve(__dirname, '../.env') }));
|
||||||
|
dotenvExpand.expand(dotenv.config());
|
||||||
|
|
||||||
|
// Fallback: wenn DATABASE_URL nicht direkt gesetzt ist (oder Substitution
|
||||||
|
// nicht funktioniert hat), aus den DB_*-Komponenten zusammenbauen.
|
||||||
|
if (!process.env.DATABASE_URL && process.env.DB_USER && process.env.DB_PASSWORD && process.env.DB_NAME) {
|
||||||
|
const u = encodeURIComponent(process.env.DB_USER);
|
||||||
|
const p = encodeURIComponent(process.env.DB_PASSWORD);
|
||||||
|
const h = process.env.DB_HOST || 'localhost';
|
||||||
|
const port = process.env.DB_PORT || '3306';
|
||||||
|
process.env.DATABASE_URL = `mysql://${u}:${p}@${h}:${port}/${process.env.DB_NAME}`;
|
||||||
|
}
|
||||||
|
|
||||||
import authRoutes from './routes/auth.routes.js';
|
import authRoutes from './routes/auth.routes.js';
|
||||||
import customerRoutes from './routes/customer.routes.js';
|
import customerRoutes from './routes/customer.routes.js';
|
||||||
@@ -43,8 +68,6 @@ import { auditContextMiddleware } from './middleware/auditContext.js';
|
|||||||
import { auditMiddleware } from './middleware/audit.js';
|
import { auditMiddleware } from './middleware/audit.js';
|
||||||
import { authenticate } from './middleware/auth.js';
|
import { authenticate } from './middleware/auth.js';
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
// ==================== SECURITY: Pflicht-Umgebungsvariablen prüfen ====================
|
// ==================== SECURITY: Pflicht-Umgebungsvariablen prüfen ====================
|
||||||
if (!process.env.JWT_SECRET || process.env.JWT_SECRET.length < 32) {
|
if (!process.env.JWT_SECRET || process.env.JWT_SECRET.length < 32) {
|
||||||
console.error('❌ JWT_SECRET ist nicht gesetzt oder zu kurz (min. 32 Zeichen)');
|
console.error('❌ JWT_SECRET ist nicht gesetzt oder zu kurz (min. 32 Zeichen)');
|
||||||
@@ -73,12 +96,102 @@ app.set('trust proxy', 'loopback');
|
|||||||
|
|
||||||
// ==================== SECURITY MIDDLEWARE ====================
|
// ==================== SECURITY MIDDLEWARE ====================
|
||||||
|
|
||||||
// HTTP Security Headers (X-Frame-Options, X-Content-Type-Options, HSTS, etc.)
|
// HTTP Security Headers (X-Frame-Options, X-Content-Type-Options, HSTS, CSP, ...)
|
||||||
|
//
|
||||||
|
// CSP ist konservativ aber SPA-tauglich:
|
||||||
|
// - script-src 'self' → keine externen Skripte, keine inline-Scripts
|
||||||
|
// (Vite baut Module-Skripte zu separaten Files,
|
||||||
|
// die sind 'self')
|
||||||
|
// - style-src 'self' 'unsafe-inline' → Tailwind/inline-Styles brauchen das
|
||||||
|
// (sicheres Trade-off; XSS via CSS ist
|
||||||
|
// marginal vs Lock-Out gegen die UI)
|
||||||
|
// - img-src self/data/blob → base64-Avatare + blob-URLs für PDFs/Downloads
|
||||||
|
// - font-src self/data → eingebettete Fonts
|
||||||
|
// - connect-src 'self' → API + WebSocket nur zur eigenen Origin
|
||||||
|
// - frame-ancestors 'none' → Clickjacking-Schutz (ersetzt X-Frame-Options)
|
||||||
|
// - object-src 'none' → keine Flash/<object>/<embed>-Embeds
|
||||||
|
// - base-uri 'self' → keine <base>-Hijacking-Tricks
|
||||||
|
// - form-action 'self' → POST-Targets nur auf eigene Origin
|
||||||
|
// Permissions-Policy: schaltet Browser-APIs aus, die wir nicht brauchen.
|
||||||
|
// Verhindert, dass eingeschleustes JS Zugriff auf Kamera/Mikro/GPS/Payment etc.
|
||||||
|
// bekommt. clipboard-write ist 'self' für die CopyButton-Komponenten,
|
||||||
|
// fullscreen 'self' falls jemand mal eine Vorschau in Vollbild öffnet.
|
||||||
|
app.use((_req, res, next) => {
|
||||||
|
res.setHeader(
|
||||||
|
'Permissions-Policy',
|
||||||
|
[
|
||||||
|
'accelerometer=()',
|
||||||
|
'ambient-light-sensor=()',
|
||||||
|
'autoplay=()',
|
||||||
|
'battery=()',
|
||||||
|
'camera=()',
|
||||||
|
'clipboard-read=()',
|
||||||
|
'clipboard-write=(self)',
|
||||||
|
'cross-origin-isolated=()',
|
||||||
|
'display-capture=()',
|
||||||
|
'encrypted-media=()',
|
||||||
|
'fullscreen=(self)',
|
||||||
|
'geolocation=()',
|
||||||
|
'gyroscope=()',
|
||||||
|
'hid=()',
|
||||||
|
'idle-detection=()',
|
||||||
|
'magnetometer=()',
|
||||||
|
'microphone=()',
|
||||||
|
'midi=()',
|
||||||
|
'payment=()',
|
||||||
|
'picture-in-picture=()',
|
||||||
|
'publickey-credentials-get=()',
|
||||||
|
'screen-wake-lock=()',
|
||||||
|
'sync-xhr=()',
|
||||||
|
'usb=()',
|
||||||
|
'web-share=()',
|
||||||
|
'xr-spatial-tracking=()',
|
||||||
|
].join(', '),
|
||||||
|
);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
// HTTPS-only-Header (HSTS + upgrade-insecure-requests) nur setzen, wenn
|
||||||
|
// wirklich TLS davor läuft – sonst sperrt sich die App auf direkt-via-IP-
|
||||||
|
// Deployments (Browser versucht /assets/* via https zu laden → SSL-Error).
|
||||||
|
// Aktivieren mit HTTPS_ENABLED=true in der .env, sobald ein TLS-Proxy
|
||||||
|
// (Caddy/Traefik/Nginx) vor OpenCRM steht.
|
||||||
|
const httpsEnabled = process.env.HTTPS_ENABLED === 'true';
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
helmet({
|
helmet({
|
||||||
// CSP ausschalten – wird bei SPA schwierig, frontend setzt eigene CSP via meta
|
contentSecurityPolicy: {
|
||||||
contentSecurityPolicy: false,
|
useDefaults: true,
|
||||||
// Cross-Origin-Resource-Policy: "same-site" für SPA mit gleicher Origin
|
directives: {
|
||||||
|
'default-src': ["'self'"],
|
||||||
|
'script-src': ["'self'"],
|
||||||
|
'style-src': ["'self'", "'unsafe-inline'"],
|
||||||
|
'img-src': ["'self'", 'data:', 'blob:'],
|
||||||
|
'font-src': ["'self'", 'data:'],
|
||||||
|
'connect-src': ["'self'"],
|
||||||
|
// Explizit gesetzt obwohl Fallback auf default-src/script-src greift –
|
||||||
|
// ZAP markiert sonst "No-Fallback-Direktiven" als CSP-Lücke.
|
||||||
|
'worker-src': ["'self'"],
|
||||||
|
'manifest-src': ["'self'"],
|
||||||
|
'media-src': ["'self'"],
|
||||||
|
// 'self': eigene App darf eigene Resourcen in iframes embeden (z.B. die
|
||||||
|
// annotierte PDF-Vorschau in der Auftragsvorlagen-Konfiguration).
|
||||||
|
// 'none' würde sogar same-origin blocken und damit die UI brechen.
|
||||||
|
// Externe Sites bleiben weiterhin gesperrt.
|
||||||
|
'frame-ancestors': ["'self'"],
|
||||||
|
'object-src': ["'none'"],
|
||||||
|
'base-uri': ["'self'"],
|
||||||
|
'form-action': ["'self'"],
|
||||||
|
// useDefaults bringt 'upgrade-insecure-requests' selbst mit – explizit
|
||||||
|
// auf null setzen entfernt es aus dem Header (helmet-API).
|
||||||
|
'upgrade-insecure-requests': httpsEnabled ? [] : null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// HSTS NIE in Helmet senden – der vorgelagerte TLS-Reverse-Proxy
|
||||||
|
// (Nginx Proxy Manager) macht das bereits. Doppelter Header verletzt
|
||||||
|
// RFC 6797 (Multiple Header Entries) und wird von ZAP angemahnt.
|
||||||
|
// HTTPS_ENABLED-Flag bleibt für upgrade-insecure-requests (CSP) relevant.
|
||||||
|
strictTransportSecurity: false,
|
||||||
crossOriginResourcePolicy: { policy: 'same-site' },
|
crossOriginResourcePolicy: { policy: 'same-site' },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -127,6 +240,15 @@ app.get('/api/uploads/*', authenticate as any, (req, res, next) => {
|
|||||||
return (downloadFile as any)(req, res, next);
|
return (downloadFile as any)(req, res, next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Cache-Control für alle API-Responses: `no-store` verhindert, dass Shared
|
||||||
|
// Caches (CDN/Reverse-Proxy/Browser-History) JSON mit sensiblen Daten
|
||||||
|
// vorhalten. Statische Frontend-Assets unter /assets/* sind weiter cacheable
|
||||||
|
// (siehe express.static mit immutable weiter unten).
|
||||||
|
app.use('/api', (_req, res, next) => {
|
||||||
|
res.setHeader('Cache-Control', 'no-store');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Öffentliche Routes (OHNE Authentifizierung)
|
// Öffentliche Routes (OHNE Authentifizierung)
|
||||||
app.use('/api/public/consent', consentPublicRoutes);
|
app.use('/api/public/consent', consentPublicRoutes);
|
||||||
|
|
||||||
@@ -171,8 +293,29 @@ app.get('/api/health', (req, res) => {
|
|||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
const publicPath = path.join(process.cwd(), 'public');
|
const publicPath = path.join(process.cwd(), 'public');
|
||||||
|
|
||||||
// Serve static files
|
// Vite-Build-Assets (z.B. /assets/index-abc123.js) haben einen Content-Hash
|
||||||
app.use(express.static(publicPath));
|
// im Dateinamen – das Image ist also versioniert. Daher kann der Browser
|
||||||
|
// sie für ein Jahr aggressiv cachen und muss nicht revalidieren.
|
||||||
|
app.use(
|
||||||
|
'/assets',
|
||||||
|
express.static(path.join(publicPath, 'assets'), {
|
||||||
|
maxAge: '1y',
|
||||||
|
immutable: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Rest des Frontends (index.html selbst, vite.svg, robots.txt, sitemap.xml).
|
||||||
|
// express.static findet index.html bei GET /, deshalb MUSS hier das gleiche
|
||||||
|
// no-store-Verhalten greifen wie im SPA-Fallback weiter unten – sonst
|
||||||
|
// serviert der erste Static-Handler / mit dem express-Default `max-age=0`,
|
||||||
|
// bevor der Fallback überhaupt greift, und der Browser cached die alte SPA.
|
||||||
|
app.use(
|
||||||
|
express.static(publicPath, {
|
||||||
|
setHeaders: (res) => {
|
||||||
|
res.setHeader('Cache-Control', 'no-store, must-revalidate');
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// SPA fallback: serve index.html for all non-API routes
|
// SPA fallback: serve index.html for all non-API routes
|
||||||
app.get('*', (req, res, next) => {
|
app.get('*', (req, res, next) => {
|
||||||
@@ -180,6 +323,9 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
if (req.path.startsWith('/api')) {
|
if (req.path.startsWith('/api')) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
// SPA-Wurzel darf NIE gecached werden – sonst sieht der Browser nach einem
|
||||||
|
// Deploy weiterhin die alte index.html mit alten Asset-Hashes.
|
||||||
|
res.setHeader('Cache-Control', 'no-store, must-revalidate');
|
||||||
res.sendFile(path.join(publicPath, 'index.html'));
|
res.sendFile(path.join(publicPath, 'index.html'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ router.delete('/:id', authenticate, requirePermission('contracts:delete'), contr
|
|||||||
// Follow-up contract
|
// Follow-up contract
|
||||||
router.post('/:id/follow-up', authenticate, requirePermission('contracts:create'), contractController.createFollowUp);
|
router.post('/:id/follow-up', authenticate, requirePermission('contracts:create'), contractController.createFollowUp);
|
||||||
|
|
||||||
|
// VVL (Vertragsverlängerung beim selben Anbieter, vollständige Kopie + Datums-Berechnung)
|
||||||
|
router.post('/:id/renewal', authenticate, requirePermission('contracts:create'), contractController.createRenewal);
|
||||||
|
|
||||||
// Snooze (Vertrag zurückstellen)
|
// Snooze (Vertrag zurückstellen)
|
||||||
router.patch('/:id/snooze', authenticate, requirePermission('contracts:update'), contractController.snoozeContract);
|
router.patch('/:id/snooze', authenticate, requirePermission('contracts:update'), contractController.snoozeContract);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
import multer from 'multer';
|
||||||
import * as factoryDefaultsController from '../controllers/factoryDefaults.controller.js';
|
import * as factoryDefaultsController from '../controllers/factoryDefaults.controller.js';
|
||||||
import { authenticate, requirePermission } from '../middleware/auth.js';
|
import { authenticate, requirePermission } from '../middleware/auth.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
// In-Memory-Upload für die ZIP – wird direkt verarbeitet, keine temporäre Datei.
|
||||||
|
const upload = multer({
|
||||||
|
storage: multer.memoryStorage(),
|
||||||
|
fileFilter: (_req, file, cb) => {
|
||||||
|
const ok =
|
||||||
|
file.mimetype === 'application/zip' ||
|
||||||
|
file.mimetype === 'application/x-zip-compressed' ||
|
||||||
|
file.mimetype === 'application/octet-stream' || // manche Browser senden das für .zip
|
||||||
|
file.originalname.toLowerCase().endsWith('.zip');
|
||||||
|
if (ok) cb(null, true);
|
||||||
|
else cb(new Error('Nur ZIP-Dateien sind erlaubt'));
|
||||||
|
},
|
||||||
|
limits: { fileSize: 50 * 1024 * 1024 },
|
||||||
|
});
|
||||||
|
|
||||||
// Preview (was wäre im Export drin?)
|
// Preview (was wäre im Export drin?)
|
||||||
router.get(
|
router.get(
|
||||||
'/preview',
|
'/preview',
|
||||||
@@ -20,4 +36,13 @@ router.get(
|
|||||||
factoryDefaultsController.exportFactoryDefaults,
|
factoryDefaultsController.exportFactoryDefaults,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Import aus ZIP (multipart, Feld 'zip')
|
||||||
|
router.post(
|
||||||
|
'/import',
|
||||||
|
authenticate,
|
||||||
|
requirePermission('settings:update'),
|
||||||
|
upload.single('zip'),
|
||||||
|
factoryDefaultsController.importFactoryDefaults,
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ export async function createBackup(): Promise<BackupResult> {
|
|||||||
{ name: 'EmailLog', query: () => prisma.emailLog.findMany() },
|
{ name: 'EmailLog', query: () => prisma.emailLog.findMany() },
|
||||||
{ name: 'AuditRetentionPolicy', query: () => prisma.auditRetentionPolicy.findMany() },
|
{ name: 'AuditRetentionPolicy', query: () => prisma.auditRetentionPolicy.findMany() },
|
||||||
{ name: 'AuditLog', query: () => prisma.auditLog.findMany() },
|
{ name: 'AuditLog', query: () => prisma.auditLog.findMany() },
|
||||||
|
{ name: 'SecurityEvent', query: () => prisma.securityEvent.findMany() },
|
||||||
];
|
];
|
||||||
|
|
||||||
let totalRecords = 0;
|
let totalRecords = 0;
|
||||||
@@ -310,6 +311,7 @@ export async function restoreBackup(backupName: string): Promise<RestoreResult>
|
|||||||
// Logs & Audit zuerst (hängen an allem)
|
// Logs & Audit zuerst (hängen an allem)
|
||||||
await prisma.auditLog.deleteMany({});
|
await prisma.auditLog.deleteMany({});
|
||||||
await prisma.emailLog.deleteMany({});
|
await prisma.emailLog.deleteMany({});
|
||||||
|
await prisma.securityEvent.deleteMany({});
|
||||||
|
|
||||||
// Detail-Tabellen
|
// Detail-Tabellen
|
||||||
await prisma.carInsuranceDetails.deleteMany({});
|
await prisma.carInsuranceDetails.deleteMany({});
|
||||||
@@ -887,6 +889,18 @@ export async function restoreBackup(backupName: string): Promise<RestoreResult>
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'SecurityEvent',
|
||||||
|
restore: async (data: any[]) => {
|
||||||
|
for (const item of data) {
|
||||||
|
await prisma.securityEvent.upsert({
|
||||||
|
where: { id: item.id },
|
||||||
|
update: convertDates(item),
|
||||||
|
create: convertDates(item),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let totalRestored = 0;
|
let totalRestored = 0;
|
||||||
|
|||||||
@@ -765,6 +765,251 @@ export async function createFollowUpContract(previousContractId: number) {
|
|||||||
return createContract(newContractData);
|
return createContract(newContractData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hilfsfunktion: extrahiert die Anzahl Monate aus einer ContractDuration.
|
||||||
|
* Code-Beispiele: "12M", "24M", "1J", "2J". Falls nichts erkannt wird, fällt
|
||||||
|
* sie auf 12 Monate als sicheren Default zurück.
|
||||||
|
*/
|
||||||
|
function durationToMonths(code: string | null | undefined, description: string | null | undefined): number {
|
||||||
|
const c = (code || '').trim();
|
||||||
|
const d = (description || '').trim();
|
||||||
|
let m = c.match(/^(\d+)\s*M$/i);
|
||||||
|
if (m) return parseInt(m[1], 10);
|
||||||
|
m = c.match(/^(\d+)\s*J$/i);
|
||||||
|
if (m) return parseInt(m[1], 10) * 12;
|
||||||
|
m = d.match(/(\d+)\s*Monat/i);
|
||||||
|
if (m) return parseInt(m[1], 10);
|
||||||
|
m = d.match(/(\d+)\s*Jahr/i);
|
||||||
|
if (m) return parseInt(m[1], 10) * 12;
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VVL = Vertragsverlängerung beim selben Anbieter.
|
||||||
|
*
|
||||||
|
* Im Gegensatz zu createFollowUpContract werden ALLE Daten 1:1 kopiert:
|
||||||
|
* Provider, Tarif, Portal-Credentials, Preise, Notes, ContractDocuments.
|
||||||
|
*
|
||||||
|
* Berechnet wird das neue Startdatum: altes startDate + Vertragslaufzeit.
|
||||||
|
* Stimmt das gefundene Datum nicht mit dem späteren Auftrag überein, kann
|
||||||
|
* der User es im Vertrag manuell anpassen.
|
||||||
|
*
|
||||||
|
* NICHT mitkopiert wird:
|
||||||
|
* - das Auftragsdokument (documentType "Auftragsformular") – das ist
|
||||||
|
* schließlich die NEU zu unterschreibende VVL.
|
||||||
|
* - Kündigungsschreiben/-bestätigung (das war der ALTE Cancel-Flow,
|
||||||
|
* bei einer VVL nicht relevant)
|
||||||
|
*/
|
||||||
|
export async function createRenewalContract(previousContractId: number) {
|
||||||
|
const previousContract = await getContractById(previousContractId, true);
|
||||||
|
if (!previousContract) {
|
||||||
|
throw new Error('Vorgängervertrag nicht gefunden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bereits ein Folge-/VVL-Vertrag vorhanden?
|
||||||
|
const existing = await prisma.contract.findFirst({
|
||||||
|
where: { previousContractId },
|
||||||
|
select: { id: true, contractNumber: true },
|
||||||
|
});
|
||||||
|
if (existing) {
|
||||||
|
throw new Error(`Es existiert bereits ein Folgevertrag: ${existing.contractNumber}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neues Startdatum = altes Start + Laufzeit
|
||||||
|
let newStartDate: Date | null = null;
|
||||||
|
let newEndDate: Date | null = null;
|
||||||
|
if (previousContract.startDate && previousContract.contractDuration) {
|
||||||
|
const months = durationToMonths(
|
||||||
|
previousContract.contractDuration.code,
|
||||||
|
previousContract.contractDuration.description,
|
||||||
|
);
|
||||||
|
newStartDate = new Date(previousContract.startDate);
|
||||||
|
newStartDate.setMonth(newStartDate.getMonth() + months);
|
||||||
|
newEndDate = new Date(newStartDate);
|
||||||
|
newEndDate.setMonth(newEndDate.getMonth() + months);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vertrags-Daten 1:1 kopieren (außer id/contractNumber/Datums-/Cancellation-Felder)
|
||||||
|
const contractNumber = generateContractNumber(previousContract.type);
|
||||||
|
|
||||||
|
const newContract = await prisma.contract.create({
|
||||||
|
data: {
|
||||||
|
contractNumber,
|
||||||
|
customerId: previousContract.customerId,
|
||||||
|
type: previousContract.type,
|
||||||
|
status: 'DRAFT',
|
||||||
|
contractCategoryId: previousContract.contractCategoryId,
|
||||||
|
addressId: previousContract.addressId,
|
||||||
|
billingAddressId: previousContract.billingAddressId,
|
||||||
|
bankCardId: previousContract.bankCardId,
|
||||||
|
identityDocumentId: previousContract.identityDocumentId,
|
||||||
|
salesPlatformId: previousContract.salesPlatformId,
|
||||||
|
cancellationPeriodId: previousContract.cancellationPeriodId,
|
||||||
|
contractDurationId: previousContract.contractDurationId,
|
||||||
|
previousContractId: previousContract.id,
|
||||||
|
previousProviderId: previousContract.previousProviderId,
|
||||||
|
providerId: previousContract.providerId,
|
||||||
|
tariffId: previousContract.tariffId,
|
||||||
|
providerName: previousContract.providerName,
|
||||||
|
tariffName: previousContract.tariffName,
|
||||||
|
customerNumberAtProvider: previousContract.customerNumberAtProvider,
|
||||||
|
portalUsername: previousContract.portalUsername,
|
||||||
|
portalPasswordEncrypted: previousContract.portalPasswordEncrypted,
|
||||||
|
commission: previousContract.commission,
|
||||||
|
notes: previousContract.notes,
|
||||||
|
startDate: newStartDate,
|
||||||
|
endDate: newEndDate,
|
||||||
|
// Cancellation-Felder bewusst leer lassen – die VVL hat den alten
|
||||||
|
// Cancel-Flow nicht geerbt.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Detail-Tabellen 1:1 kopieren (id rausnehmen, contractId neu)
|
||||||
|
if (previousContract.energyDetails) {
|
||||||
|
const ed = previousContract.energyDetails;
|
||||||
|
const newEnergy = await prisma.energyContractDetails.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
meterId: ed.meterId,
|
||||||
|
maloId: ed.maloId,
|
||||||
|
annualConsumption: ed.annualConsumption,
|
||||||
|
annualConsumptionKwh: ed.annualConsumptionKwh,
|
||||||
|
basePrice: ed.basePrice,
|
||||||
|
unitPrice: ed.unitPrice,
|
||||||
|
unitPriceNt: ed.unitPriceNt,
|
||||||
|
bonus: ed.bonus,
|
||||||
|
previousProviderName: ed.previousProviderName,
|
||||||
|
previousCustomerNumber: ed.previousCustomerNumber,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// ContractMeter-Verknüpfungen mitkopieren
|
||||||
|
for (const cm of ed.contractMeters || []) {
|
||||||
|
await prisma.contractMeter.create({
|
||||||
|
data: {
|
||||||
|
energyContractDetailsId: newEnergy.id,
|
||||||
|
meterId: cm.meterId,
|
||||||
|
position: cm.position,
|
||||||
|
installedAt: cm.installedAt,
|
||||||
|
removedAt: cm.removedAt,
|
||||||
|
finalReading: cm.finalReading,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previousContract.internetDetails) {
|
||||||
|
const id = previousContract.internetDetails;
|
||||||
|
const newInet = await prisma.internetContractDetails.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
downloadSpeed: id.downloadSpeed,
|
||||||
|
uploadSpeed: id.uploadSpeed,
|
||||||
|
routerModel: id.routerModel,
|
||||||
|
routerSerialNumber: id.routerSerialNumber,
|
||||||
|
installationDate: id.installationDate,
|
||||||
|
internetUsername: id.internetUsername,
|
||||||
|
internetPasswordEncrypted: id.internetPasswordEncrypted,
|
||||||
|
propertyType: id.propertyType,
|
||||||
|
propertyLocation: id.propertyLocation,
|
||||||
|
connectionLocation: id.connectionLocation,
|
||||||
|
homeId: id.homeId,
|
||||||
|
activationCode: id.activationCode,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
for (const pn of id.phoneNumbers || []) {
|
||||||
|
await prisma.phoneNumber.create({
|
||||||
|
data: {
|
||||||
|
internetContractDetailsId: newInet.id,
|
||||||
|
phoneNumber: pn.phoneNumber,
|
||||||
|
isMain: pn.isMain,
|
||||||
|
sipUsername: pn.sipUsername,
|
||||||
|
sipPasswordEncrypted: pn.sipPasswordEncrypted,
|
||||||
|
sipServer: pn.sipServer,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previousContract.mobileDetails) {
|
||||||
|
const md = previousContract.mobileDetails;
|
||||||
|
const newMob = await prisma.mobileContractDetails.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
requiresMultisim: md.requiresMultisim,
|
||||||
|
dataVolume: md.dataVolume,
|
||||||
|
includedMinutes: md.includedMinutes,
|
||||||
|
includedSMS: md.includedSMS,
|
||||||
|
deviceModel: md.deviceModel,
|
||||||
|
deviceImei: md.deviceImei,
|
||||||
|
phoneNumber: md.phoneNumber,
|
||||||
|
simCardNumber: md.simCardNumber,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
for (const sc of md.simCards || []) {
|
||||||
|
await prisma.simCard.create({
|
||||||
|
data: {
|
||||||
|
mobileDetailsId: newMob.id,
|
||||||
|
phoneNumber: sc.phoneNumber,
|
||||||
|
simCardNumber: sc.simCardNumber,
|
||||||
|
isMultisim: sc.isMultisim,
|
||||||
|
isMain: sc.isMain,
|
||||||
|
pin: sc.pin,
|
||||||
|
puk: sc.puk,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previousContract.tvDetails) {
|
||||||
|
await prisma.tvContractDetails.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
receiverModel: previousContract.tvDetails.receiverModel,
|
||||||
|
smartcardNumber: previousContract.tvDetails.smartcardNumber,
|
||||||
|
package: previousContract.tvDetails.package,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (previousContract.carInsuranceDetails) {
|
||||||
|
const ci = previousContract.carInsuranceDetails;
|
||||||
|
await prisma.carInsuranceDetails.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
licensePlate: ci.licensePlate,
|
||||||
|
hsn: ci.hsn,
|
||||||
|
tsn: ci.tsn,
|
||||||
|
vin: ci.vin,
|
||||||
|
vehicleType: ci.vehicleType,
|
||||||
|
firstRegistration: ci.firstRegistration,
|
||||||
|
noClaimsClass: ci.noClaimsClass,
|
||||||
|
insuranceType: ci.insuranceType,
|
||||||
|
deductiblePartial: ci.deductiblePartial,
|
||||||
|
deductibleFull: ci.deductibleFull,
|
||||||
|
previousInsurer: ci.previousInsurer,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractDocuments mitkopieren – AUSSER "Auftragsformular" (das ist die
|
||||||
|
// neue Unterschrift, die der User selbst hochlädt). Files werden NICHT
|
||||||
|
// physisch dupliziert; beide Verträge zeigen auf dieselbe Datei.
|
||||||
|
const docs = await prisma.contractDocument.findMany({
|
||||||
|
where: { contractId: previousContract.id },
|
||||||
|
});
|
||||||
|
for (const d of docs) {
|
||||||
|
if (d.documentType.toLowerCase().includes('auftragsformular')) continue;
|
||||||
|
await prisma.contractDocument.create({
|
||||||
|
data: {
|
||||||
|
contractId: newContract.id,
|
||||||
|
documentType: d.documentType,
|
||||||
|
documentPath: d.documentPath,
|
||||||
|
originalName: d.originalName,
|
||||||
|
notes: d.notes,
|
||||||
|
uploadedBy: d.uploadedBy,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return prisma.contract.findUnique({ where: { id: newContract.id } });
|
||||||
|
}
|
||||||
|
|
||||||
// Decrypt password for viewing
|
// Decrypt password for viewing
|
||||||
export async function getContractPassword(id: number): Promise<string | null> {
|
export async function getContractPassword(id: number): Promise<string | null> {
|
||||||
const contract = await prisma.contract.findUnique({
|
const contract = await prisma.contract.findUnique({
|
||||||
|
|||||||
@@ -129,3 +129,35 @@ export async function createNewContractFromPredecessorEntry(
|
|||||||
createdBy,
|
createdBy,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatischen Historie-Eintrag für VVL (Vertragsverlängerung) im Vorgängervertrag.
|
||||||
|
*/
|
||||||
|
export async function createRenewalHistoryEntry(
|
||||||
|
previousContractId: number,
|
||||||
|
newContractNumber: string,
|
||||||
|
createdBy: string
|
||||||
|
) {
|
||||||
|
return createHistoryEntry(previousContractId, {
|
||||||
|
title: `Vertragsverlängerung erstellt: ${newContractNumber}`,
|
||||||
|
description: `Eine Vertragsverlängerung (VVL) als ${newContractNumber} wurde aus diesem Vertrag erstellt – alle Daten wurden 1:1 übernommen, das Auftragsdokument muss neu hochgeladen werden.`,
|
||||||
|
isAutomatic: true,
|
||||||
|
createdBy,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatischen Historie-Eintrag im neuen VVL-Vertrag.
|
||||||
|
*/
|
||||||
|
export async function createNewRenewalFromPredecessorEntry(
|
||||||
|
newContractId: number,
|
||||||
|
previousContractNumber: string,
|
||||||
|
createdBy: string
|
||||||
|
) {
|
||||||
|
return createHistoryEntry(newContractId, {
|
||||||
|
title: `VVL zu ${previousContractNumber}`,
|
||||||
|
description: `Dieser Vertrag wurde als Vertragsverlängerung (VVL) zu ${previousContractNumber} erstellt.`,
|
||||||
|
isAutomatic: true,
|
||||||
|
createdBy,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,32 @@
|
|||||||
/**
|
/**
|
||||||
* Factory-Defaults: Export + Import von Stammdaten-Katalogen.
|
* Factory-Defaults: Export + Import von Stammdaten-Katalogen.
|
||||||
* Enthält KEINE Kundendaten, Verträge, Dokumente oder Einstellungen –
|
* Enthält KEINE Kundendaten, Verträge, Dokumente oder E-Mails –
|
||||||
* nur reine Kataloge: Anbieter, Tarife, Kündigungsfristen, Laufzeiten,
|
* nur reine Kataloge: Anbieter, Tarife, Kündigungsfristen, Laufzeiten,
|
||||||
* Vertragskategorien und PDF-Auftragsvorlagen.
|
* Vertragskategorien, PDF-Auftragsvorlagen und ausgewählte
|
||||||
|
* HTML-Templates (Datenschutz / Impressum / Vollmacht).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import archiver from 'archiver';
|
import archiver from 'archiver';
|
||||||
|
import AdmZip from 'adm-zip';
|
||||||
import prisma from '../lib/prisma.js';
|
import prisma from '../lib/prisma.js';
|
||||||
|
|
||||||
|
// Whitelist der AppSetting-Keys, die ins Factory-Default-Bundle gehören.
|
||||||
|
// Bewusst klein gehalten: nur HTML-Templates für rechtliche Standardtexte –
|
||||||
|
// keine Secrets, keine SMTP-Konfiguration, keine User-spezifischen Settings.
|
||||||
|
export const FACTORY_DEFAULT_APP_SETTING_KEYS = [
|
||||||
|
'privacyPolicyHtml',
|
||||||
|
'authorizationTemplateHtml',
|
||||||
|
'imprintHtml',
|
||||||
|
'websitePrivacyPolicyHtml',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export interface AppSettingExport {
|
||||||
|
key: (typeof FACTORY_DEFAULT_APP_SETTING_KEYS)[number];
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FactoryDefaultsManifest {
|
export interface FactoryDefaultsManifest {
|
||||||
version: 1;
|
version: 1;
|
||||||
exportedAt: string;
|
exportedAt: string;
|
||||||
@@ -20,6 +37,7 @@ export interface FactoryDefaultsManifest {
|
|||||||
contractDurations: number;
|
contractDurations: number;
|
||||||
contractCategories: number;
|
contractCategories: number;
|
||||||
pdfTemplates: number;
|
pdfTemplates: number;
|
||||||
|
appSettings: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +67,7 @@ export interface PdfTemplateExport {
|
|||||||
* Sammelt alle Katalog-Daten aus der DB.
|
* Sammelt alle Katalog-Daten aus der DB.
|
||||||
*/
|
*/
|
||||||
export async function collectFactoryDefaults() {
|
export async function collectFactoryDefaults() {
|
||||||
const [providers, cancellationPeriods, contractDurations, contractCategories, pdfTemplates] =
|
const [providers, cancellationPeriods, contractDurations, contractCategories, pdfTemplates, appSettings] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
prisma.provider.findMany({
|
prisma.provider.findMany({
|
||||||
include: { tariffs: { select: { name: true, isActive: true } } },
|
include: { tariffs: { select: { name: true, isActive: true } } },
|
||||||
@@ -59,6 +77,11 @@ export async function collectFactoryDefaults() {
|
|||||||
prisma.contractDuration.findMany({ orderBy: { code: 'asc' } }),
|
prisma.contractDuration.findMany({ orderBy: { code: 'asc' } }),
|
||||||
prisma.contractCategory.findMany({ orderBy: { sortOrder: 'asc' } }),
|
prisma.contractCategory.findMany({ orderBy: { sortOrder: 'asc' } }),
|
||||||
prisma.pdfTemplate.findMany({ orderBy: { name: 'asc' } }),
|
prisma.pdfTemplate.findMany({ orderBy: { name: 'asc' } }),
|
||||||
|
prisma.appSetting.findMany({
|
||||||
|
where: { key: { in: [...FACTORY_DEFAULT_APP_SETTING_KEYS] } },
|
||||||
|
select: { key: true, value: true },
|
||||||
|
orderBy: { key: 'asc' },
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -108,6 +131,7 @@ export async function collectFactoryDefaults() {
|
|||||||
pdfFilename: sanitizeFilename(t.name) + path.extname(t.originalName || '.pdf'),
|
pdfFilename: sanitizeFilename(t.name) + path.extname(t.originalName || '.pdf'),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
appSettings: appSettings as AppSettingExport[],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +156,7 @@ export async function exportFactoryDefaults(): Promise<Buffer> {
|
|||||||
contractDurations: data.contractDurations.length,
|
contractDurations: data.contractDurations.length,
|
||||||
contractCategories: data.contractCategories.length,
|
contractCategories: data.contractCategories.length,
|
||||||
pdfTemplates: data.pdfTemplates.length,
|
pdfTemplates: data.pdfTemplates.length,
|
||||||
|
appSettings: data.appSettings.length,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -160,6 +185,9 @@ export async function exportFactoryDefaults(): Promise<Buffer> {
|
|||||||
archive.append(JSON.stringify(data.pdfTemplates, null, 2), {
|
archive.append(JSON.stringify(data.pdfTemplates, null, 2), {
|
||||||
name: 'pdf-templates/pdf-templates.json',
|
name: 'pdf-templates/pdf-templates.json',
|
||||||
});
|
});
|
||||||
|
archive.append(JSON.stringify(data.appSettings, null, 2), {
|
||||||
|
name: 'app-settings/app-settings.json',
|
||||||
|
});
|
||||||
|
|
||||||
// PDF-Dateien physisch hinzufügen (Pfade aus DB laden)
|
// PDF-Dateien physisch hinzufügen (Pfade aus DB laden)
|
||||||
const uploadsRoot = path.join(process.cwd(), 'uploads');
|
const uploadsRoot = path.join(process.cwd(), 'uploads');
|
||||||
@@ -192,3 +220,244 @@ export async function exportFactoryDefaults(): Promise<Buffer> {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IMPORT
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
export interface FactoryDefaultsImportResult {
|
||||||
|
providers: number;
|
||||||
|
tariffs: number;
|
||||||
|
cancellationPeriods: number;
|
||||||
|
contractDurations: number;
|
||||||
|
contractCategories: number;
|
||||||
|
pdfTemplates: number;
|
||||||
|
pdfTemplatesSkipped: number;
|
||||||
|
appSettings: number;
|
||||||
|
warnings: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJsonEntry<T>(zip: AdmZip, name: string): T[] {
|
||||||
|
const entry = zip.getEntry(name);
|
||||||
|
if (!entry) return [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(entry.getData().toString('utf-8'));
|
||||||
|
return Array.isArray(parsed) ? parsed : [];
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wendet ein Factory-Defaults-ZIP idempotent auf die DB an.
|
||||||
|
* - upsert über unique-Keys: nichts wird gelöscht
|
||||||
|
* - PDFs landen in `${uploads}/pdf-templates/` mit eindeutigem Suffix
|
||||||
|
* - AppSettings nur Whitelist-Keys (FACTORY_DEFAULT_APP_SETTING_KEYS)
|
||||||
|
*
|
||||||
|
* Robust gegen Zip-Slip: wir greifen nur auf bekannte Entry-Namen zu
|
||||||
|
* (`pdf-templates/<basename>`), niemals auf einen aus dem ZIP konstruierten
|
||||||
|
* Pfad im Filesystem.
|
||||||
|
*/
|
||||||
|
export async function importFactoryDefaults(
|
||||||
|
zipBuffer: Buffer,
|
||||||
|
): Promise<FactoryDefaultsImportResult> {
|
||||||
|
const zip = new AdmZip(zipBuffer);
|
||||||
|
const result: FactoryDefaultsImportResult = {
|
||||||
|
providers: 0,
|
||||||
|
tariffs: 0,
|
||||||
|
cancellationPeriods: 0,
|
||||||
|
contractDurations: 0,
|
||||||
|
contractCategories: 0,
|
||||||
|
pdfTemplates: 0,
|
||||||
|
pdfTemplatesSkipped: 0,
|
||||||
|
appSettings: 0,
|
||||||
|
warnings: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Providers + Tariffs
|
||||||
|
const providers = parseJsonEntry<ProviderExport>(zip, 'providers/providers.json');
|
||||||
|
for (const p of providers) {
|
||||||
|
if (!p.name) continue;
|
||||||
|
const provider = await prisma.provider.upsert({
|
||||||
|
where: { name: p.name },
|
||||||
|
update: {
|
||||||
|
portalUrl: p.portalUrl ?? null,
|
||||||
|
usernameFieldName: p.usernameFieldName ?? null,
|
||||||
|
passwordFieldName: p.passwordFieldName ?? null,
|
||||||
|
isActive: p.isActive ?? true,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
name: p.name,
|
||||||
|
portalUrl: p.portalUrl ?? null,
|
||||||
|
usernameFieldName: p.usernameFieldName ?? null,
|
||||||
|
passwordFieldName: p.passwordFieldName ?? null,
|
||||||
|
isActive: p.isActive ?? true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
result.providers++;
|
||||||
|
for (const t of p.tariffs ?? []) {
|
||||||
|
if (!t.name) continue;
|
||||||
|
await prisma.tariff.upsert({
|
||||||
|
where: { providerId_name: { providerId: provider.id, name: t.name } },
|
||||||
|
update: { isActive: t.isActive ?? true },
|
||||||
|
create: { providerId: provider.id, name: t.name, isActive: t.isActive ?? true },
|
||||||
|
});
|
||||||
|
result.tariffs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Contract-Meta
|
||||||
|
const cancellationPeriods = parseJsonEntry<{ code: string; description: string; isActive?: boolean }>(
|
||||||
|
zip,
|
||||||
|
'contract-meta/cancellation-periods.json',
|
||||||
|
);
|
||||||
|
for (const c of cancellationPeriods) {
|
||||||
|
if (!c.code || !c.description) continue;
|
||||||
|
await prisma.cancellationPeriod.upsert({
|
||||||
|
where: { code: c.code },
|
||||||
|
update: { description: c.description, isActive: c.isActive ?? true },
|
||||||
|
create: { code: c.code, description: c.description, isActive: c.isActive ?? true },
|
||||||
|
});
|
||||||
|
result.cancellationPeriods++;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contractDurations = parseJsonEntry<{ code: string; description: string; isActive?: boolean }>(
|
||||||
|
zip,
|
||||||
|
'contract-meta/contract-durations.json',
|
||||||
|
);
|
||||||
|
for (const d of contractDurations) {
|
||||||
|
if (!d.code || !d.description) continue;
|
||||||
|
await prisma.contractDuration.upsert({
|
||||||
|
where: { code: d.code },
|
||||||
|
update: { description: d.description, isActive: d.isActive ?? true },
|
||||||
|
create: { code: d.code, description: d.description, isActive: d.isActive ?? true },
|
||||||
|
});
|
||||||
|
result.contractDurations++;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contractCategories = parseJsonEntry<{
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
icon?: string | null;
|
||||||
|
color?: string | null;
|
||||||
|
sortOrder?: number;
|
||||||
|
isActive?: boolean;
|
||||||
|
}>(zip, 'contract-meta/contract-categories.json');
|
||||||
|
for (const c of contractCategories) {
|
||||||
|
if (!c.code || !c.name) continue;
|
||||||
|
await prisma.contractCategory.upsert({
|
||||||
|
where: { code: c.code },
|
||||||
|
update: {
|
||||||
|
name: c.name,
|
||||||
|
icon: c.icon ?? null,
|
||||||
|
color: c.color ?? null,
|
||||||
|
sortOrder: c.sortOrder ?? 0,
|
||||||
|
isActive: c.isActive ?? true,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
code: c.code,
|
||||||
|
name: c.name,
|
||||||
|
icon: c.icon ?? null,
|
||||||
|
color: c.color ?? null,
|
||||||
|
sortOrder: c.sortOrder ?? 0,
|
||||||
|
isActive: c.isActive ?? true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
result.contractCategories++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- PDF-Vorlagen (JSON + binär aus dem ZIP)
|
||||||
|
const pdfTemplates = parseJsonEntry<PdfTemplateExport>(
|
||||||
|
zip,
|
||||||
|
'pdf-templates/pdf-templates.json',
|
||||||
|
);
|
||||||
|
if (pdfTemplates.length > 0) {
|
||||||
|
const uploadsRoot = path.join(process.cwd(), 'uploads');
|
||||||
|
const pdfDestDir = path.join(uploadsRoot, 'pdf-templates');
|
||||||
|
if (!fs.existsSync(pdfDestDir)) {
|
||||||
|
fs.mkdirSync(pdfDestDir, { recursive: true });
|
||||||
|
}
|
||||||
|
for (const t of pdfTemplates) {
|
||||||
|
if (!t.name || !t.pdfFilename) continue;
|
||||||
|
// Anti-Zip-Slip: nur basename verwenden, kein Pfad
|
||||||
|
const basename = path.basename(t.pdfFilename);
|
||||||
|
const entry = zip.getEntry(`pdf-templates/${basename}`);
|
||||||
|
if (!entry) {
|
||||||
|
result.pdfTemplatesSkipped++;
|
||||||
|
result.warnings.push(`PDF fehlt im ZIP: ${basename} – Vorlage "${t.name}" übersprungen`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ext = path.extname(t.originalName || basename) || '.pdf';
|
||||||
|
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
||||||
|
const safeName = t.name.replace(/[^a-zA-Z0-9]/g, '-');
|
||||||
|
const destFilename = `seed-${safeName}-${uniqueSuffix}${ext}`;
|
||||||
|
const destPdf = path.join(pdfDestDir, destFilename);
|
||||||
|
const relativePath = `/uploads/pdf-templates/${destFilename}`;
|
||||||
|
|
||||||
|
fs.writeFileSync(destPdf, entry.getData());
|
||||||
|
|
||||||
|
// Bei existierender Vorlage die alte Datei aufräumen
|
||||||
|
const existing = await prisma.pdfTemplate.findUnique({ where: { name: t.name } });
|
||||||
|
if (existing?.templatePath) {
|
||||||
|
const oldRel = existing.templatePath.startsWith('/uploads/')
|
||||||
|
? existing.templatePath.substring('/uploads/'.length)
|
||||||
|
: existing.templatePath;
|
||||||
|
const oldAbs = path.join(uploadsRoot, oldRel);
|
||||||
|
if (fs.existsSync(oldAbs)) {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(oldAbs);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldMappingJson = JSON.stringify(t.fieldMapping ?? {});
|
||||||
|
await prisma.pdfTemplate.upsert({
|
||||||
|
where: { name: t.name },
|
||||||
|
update: {
|
||||||
|
description: t.description ?? null,
|
||||||
|
providerName: t.providerName ?? null,
|
||||||
|
templatePath: relativePath,
|
||||||
|
originalName: t.originalName,
|
||||||
|
fieldMapping: fieldMappingJson,
|
||||||
|
phoneFieldPrefix: t.phoneFieldPrefix ?? null,
|
||||||
|
maxPhoneFields: t.maxPhoneFields ?? 8,
|
||||||
|
isActive: t.isActive ?? true,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
name: t.name,
|
||||||
|
description: t.description ?? null,
|
||||||
|
providerName: t.providerName ?? null,
|
||||||
|
templatePath: relativePath,
|
||||||
|
originalName: t.originalName,
|
||||||
|
fieldMapping: fieldMappingJson,
|
||||||
|
phoneFieldPrefix: t.phoneFieldPrefix ?? null,
|
||||||
|
maxPhoneFields: t.maxPhoneFields ?? 8,
|
||||||
|
isActive: t.isActive ?? true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
result.pdfTemplates++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- AppSettings (HTML-Templates, Whitelist)
|
||||||
|
const appSettings = parseJsonEntry<AppSettingExport>(zip, 'app-settings/app-settings.json');
|
||||||
|
const allowedKeys = new Set<string>(FACTORY_DEFAULT_APP_SETTING_KEYS);
|
||||||
|
for (const s of appSettings) {
|
||||||
|
if (!s.key || typeof s.value !== 'string') continue;
|
||||||
|
if (!allowedKeys.has(s.key)) {
|
||||||
|
result.warnings.push(`AppSetting-Key '${s.key}' nicht auf Whitelist – ignoriert`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await prisma.appSetting.upsert({
|
||||||
|
where: { key: s.key },
|
||||||
|
update: { value: s.value },
|
||||||
|
create: { key: s.key, value: s.value },
|
||||||
|
});
|
||||||
|
result.appSettings++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -155,14 +155,16 @@ export async function detectThresholds(): Promise<void> {
|
|||||||
});
|
});
|
||||||
for (const g of grouped) {
|
for (const g of grouped) {
|
||||||
if ((g._count as number) < b.threshold) continue;
|
if ((g._count as number) < b.threshold) continue;
|
||||||
// Prüfen ob wir für diese (IP+Type+Stunde) schon einen CRITICAL emittiert haben
|
// Debounce: pro IP max. 1 SUSPICIOUS-Alert pro 60min (sliding window).
|
||||||
const hourBucket = new Date(now.getTime() - (now.getTime() % (60 * 60 * 1000)));
|
// Vorher: floor(now, hour) → resettete bei Stundenwechsel und produzierte
|
||||||
|
// doppelte Alerts (Bug aus Runde 10).
|
||||||
|
const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);
|
||||||
const existing = await prisma.securityEvent.findFirst({
|
const existing = await prisma.securityEvent.findFirst({
|
||||||
where: {
|
where: {
|
||||||
type: 'SUSPICIOUS',
|
type: 'SUSPICIOUS',
|
||||||
severity: 'CRITICAL',
|
severity: 'CRITICAL',
|
||||||
ipAddress: g.ipAddress,
|
ipAddress: g.ipAddress,
|
||||||
createdAt: { gte: hourBucket },
|
createdAt: { gte: oneHourAgo },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (existing) continue;
|
if (existing) continue;
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ const USER_UPDATABLE_FIELDS = [
|
|||||||
'signalNumber',
|
'signalNumber',
|
||||||
'roleIds',
|
'roleIds',
|
||||||
'password', // nur Admin, wird im Service gehashed
|
'password', // nur Admin, wird im Service gehashed
|
||||||
|
// hasGdprAccess + hasDeveloperAccess sind keine User-Spalten – der Service
|
||||||
|
// mappt sie auf die versteckten Rollen DSGVO/Developer (siehe
|
||||||
|
// setUserGdprAccess / setUserDeveloperAccess). Müssen aber auf der Whitelist
|
||||||
|
// stehen, damit pick() sie nicht aus dem Request entfernt.
|
||||||
|
'hasGdprAccess',
|
||||||
|
'hasDeveloperAccess',
|
||||||
// Nicht: id, customerId, tokenInvalidatedAt, passwordResetToken, passwordResetExpiresAt
|
// Nicht: id, customerId, tokenInvalidatedAt, passwordResetToken, passwordResetExpiresAt
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
|||||||
+97
-11
@@ -1,4 +1,19 @@
|
|||||||
version: '3.8'
|
# OpenCRM – komplettes Setup: MariaDB + Backend/Frontend + Adminer
|
||||||
|
# Konfiguration über ./.env (siehe ./.env.example)
|
||||||
|
#
|
||||||
|
# Quick-Start (Compose v2):
|
||||||
|
# cp .env.example .env # Werte anpassen (Secrets rotieren!)
|
||||||
|
# docker compose up -d # erstes Mal: holt Images, baut Backend, startet alles
|
||||||
|
# Quick-Start (Compose v1, Legacy):
|
||||||
|
# docker-compose up -d
|
||||||
|
#
|
||||||
|
# Browser:
|
||||||
|
# http://localhost:${OPENCRM_PORT} # CRM
|
||||||
|
# http://localhost:${ADMINER_PORT} # DB-UI
|
||||||
|
#
|
||||||
|
# Daten liegen alle unter ./data/* – Bind-Mounts statt Volumes (auf Wunsch).
|
||||||
|
|
||||||
|
#version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
@@ -6,20 +21,91 @@ services:
|
|||||||
container_name: opencrm-db
|
container_name: opencrm-db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: rootpassword
|
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
||||||
MYSQL_DATABASE: opencrm
|
MARIADB_DATABASE: ${DB_NAME}
|
||||||
MYSQL_USER: opencrm
|
MARIADB_USER: ${DB_USER}
|
||||||
MYSQL_PASSWORD: opencrm123
|
MARIADB_PASSWORD: ${DB_PASSWORD}
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
# Externe Erreichbarkeit für lokale DB-Tools (TablePlus etc.).
|
||||||
|
# Auf 127.0.0.1 binden – kein public exposure.
|
||||||
|
- "127.0.0.1:${DB_PORT:-3306}:3306"
|
||||||
volumes:
|
volumes:
|
||||||
- mariadb_data:/var/lib/mysql
|
- ${DB_DATA_DIR:-./data/db}:/var/lib/mysql
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||||
start_period: 10s
|
start_period: 20s
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 3
|
retries: 5
|
||||||
|
|
||||||
volumes:
|
opencrm:
|
||||||
mariadb_data:
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: backend/Dockerfile
|
||||||
|
container_name: opencrm-app
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
# DATABASE_URL wird vom entrypoint.sh aus den DB_*-Komponenten gebaut –
|
||||||
|
# mit encodeURIComponent für Passwörter mit Sonderzeichen ($, !, #, @, :,
|
||||||
|
# / etc.). KEIN root für die App, sondern der App-User ${DB_USER}, den
|
||||||
|
# MariaDB beim ersten Start automatisch mit GRANT ALL PRIVILEGES auf
|
||||||
|
# ${DB_NAME}.* anlegt (über MARIADB_USER/MARIADB_PASSWORD).
|
||||||
|
DB_HOST: db
|
||||||
|
DB_PORT: 3306
|
||||||
|
DB_NAME: ${DB_NAME}
|
||||||
|
DB_USER: ${DB_USER}
|
||||||
|
DB_PASSWORD: ${DB_PASSWORD}
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-7d}
|
||||||
|
ENCRYPTION_KEY: ${ENCRYPTION_KEY}
|
||||||
|
NODE_ENV: production
|
||||||
|
PORT: 3001
|
||||||
|
LISTEN_ADDR: 0.0.0.0
|
||||||
|
CORS_ORIGINS: ${CORS_ORIGINS:-}
|
||||||
|
HTTPS_ENABLED: ${HTTPS_ENABLED:-false}
|
||||||
|
RUN_SEED: ${RUN_SEED:-false}
|
||||||
|
ports:
|
||||||
|
- "${OPENCRM_PORT:-3010}:3001"
|
||||||
|
volumes:
|
||||||
|
# Bind-Mounts für persistente Daten unter ./data/
|
||||||
|
- ${UPLOADS_DIR:-./data/uploads}:/app/uploads
|
||||||
|
- ${FACTORY_DEFAULTS_DIR:-./data/factory-defaults}:/app/factory-defaults
|
||||||
|
- ${BACKUPS_DIR:-./data/backups}:/app/prisma/backups
|
||||||
|
|
||||||
|
adminer:
|
||||||
|
image: adminer:latest
|
||||||
|
container_name: opencrm-adminer
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
ADMINER_DEFAULT_SERVER: db
|
||||||
|
ADMINER_DESIGN: ${ADMINER_DESIGN:-pepa-linha}
|
||||||
|
# Adminers offizieller entrypoint linkt nur Designs, deren CSS exakt
|
||||||
|
# `adminer.css` heißt. Manche Designs (dracula, adminer-dark) haben aber
|
||||||
|
# `adminer-dark.css`. Wir machen den Symlink generisch: erstes .css im
|
||||||
|
# gewählten Design wird verlinkt. Danach übergeben wir an den originalen
|
||||||
|
# entrypoint.sh.
|
||||||
|
entrypoint:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- >
|
||||||
|
cd /var/www/html;
|
||||||
|
if [ -n "$$ADMINER_DESIGN" ] && [ -d "designs/$$ADMINER_DESIGN" ]; then
|
||||||
|
CSS=$$(ls designs/$$ADMINER_DESIGN/*.css 2>/dev/null | head -1);
|
||||||
|
if [ -n "$$CSS" ]; then
|
||||||
|
ln -sf "$$CSS" adminer.css;
|
||||||
|
touch .adminer-init;
|
||||||
|
echo "[adminer-bootstrap] Theme aktiv: $$ADMINER_DESIGN -> $$CSS";
|
||||||
|
else
|
||||||
|
echo "[adminer-bootstrap] Design '$$ADMINER_DESIGN' enthält kein CSS – nutze Default";
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
exec entrypoint.sh docker-php-entrypoint "$$@"
|
||||||
|
- --
|
||||||
|
command: ["php", "-S", "[::]:8080", "-t", "/var/www/html"]
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:${ADMINER_PORT:-8090}:8080"
|
||||||
|
|||||||
@@ -97,6 +97,97 @@ isolierte Instanz (keine Multi-Tenancy im Code), Provisioning + Abrechnung
|
|||||||
|
|
||||||
## ✅ Erledigt
|
## ✅ Erledigt
|
||||||
|
|
||||||
|
- [x] **🛡️ Pentest-Hardening-Runde 11: Header-Hygiene**
|
||||||
|
- **HSTS-Doppel-Header** (18× low im Audit): Helmet's
|
||||||
|
`Strict-Transport-Security` komplett deaktiviert. Der Nginx Proxy Manager
|
||||||
|
vor der CRM-VM setzt HSTS bereits, doppelter Header verletzte RFC 6797.
|
||||||
|
- **Cache-Control** (≥10× info im Audit):
|
||||||
|
`/api/*` bekommt `no-store` (sensible JSON-Daten),
|
||||||
|
SPA-HTML (`/`, `/sitemap.xml`, `/robots.txt`, `/vite.svg`) bekommt
|
||||||
|
`no-store, must-revalidate` (sonst hängt Browser an alter index.html
|
||||||
|
fest nach Deploy),
|
||||||
|
`/assets/*` (Vite-Build mit Content-Hash im Filename) bekommt
|
||||||
|
`public, max-age=31536000, immutable`.
|
||||||
|
- **CSP No-Fallback-Direktiven** (2× medium): `worker-src`, `manifest-src`,
|
||||||
|
`media-src` explizit auf `'self'` – ZAP markiert sonst „Failure to
|
||||||
|
Define Directive with No Fallback".
|
||||||
|
- Bewusst NICHT angefasst: `style-src 'unsafe-inline'` (Tailwind/React-
|
||||||
|
inline-styles, kompletter Refactor unverhältnismäßig).
|
||||||
|
- Live verifiziert: Headers für `/`, `/api/*`, `/assets/*.js` und SPA-
|
||||||
|
Fallback-Pfade alle wie erwartet.
|
||||||
|
|
||||||
|
- [x] **🐛 PDF-Vorschau im PDF-Template-Editor lädt nicht**
|
||||||
|
- CSP-Direktive `frame-ancestors 'none'` blockte ALLE iframe-Embeddings
|
||||||
|
der eigenen Resourcen, auch same-origin – Browser zeigte je nach
|
||||||
|
Variante "Verbindung abgelehnt" oder CSP-Violation.
|
||||||
|
- Fix: `frame-ancestors 'self'` (statt `'none'`). App darf eigene
|
||||||
|
Resourcen embeden (z.B. die annotierte PDF-Vorschau), externe Sites
|
||||||
|
bleiben weiterhin gesperrt.
|
||||||
|
|
||||||
|
- [x] **🔁 Factory-Defaults Sync-Scripts (dev ↔ prod ↔ Image)**
|
||||||
|
- `./factory-export.sh` zieht eine ZIP per API in `factory-exports/`
|
||||||
|
(gitignored Drop-Box).
|
||||||
|
- `./factory-import.sh [zip]` lädt die ZIP per API in eine andere Instanz
|
||||||
|
– ohne Argument wählt es die jüngste ZIP automatisch.
|
||||||
|
- `./factory-import.sh --save-as-builtin` entpackt die ZIP zusätzlich nach
|
||||||
|
`backend/factory-defaults/` (vorher aufgeräumt). Damit landet sie beim
|
||||||
|
nächsten `docker-compose up --build` als Werkseinstellung im Image und
|
||||||
|
seedet frische DBs automatisch.
|
||||||
|
- Konfigurierbar per Env: `OPENCRM_URL`, `OPENCRM_EMAIL`,
|
||||||
|
`OPENCRM_PASSWORD` (sonst interaktive Abfrage).
|
||||||
|
- README-Abschnitt „Factory-Defaults: Stammdaten-Kataloge teilen"
|
||||||
|
komplett überarbeitet (drei Transport-Pfade, Auto-Seed, Whitelist).
|
||||||
|
|
||||||
|
- [x] **🚀 Auto-Seed: Werkseinstellungen beim Erst-Deploy**
|
||||||
|
- Inhalt von `backend/factory-defaults/` wird via Dockerfile als
|
||||||
|
`/app/factory-defaults-builtin/` ins Image gebrannt.
|
||||||
|
- Entrypoint spielt sie nach erfolgreichem Auto-Seed (frische DB) automatisch
|
||||||
|
via `tsx scripts/seed-factory-defaults.ts` ein – steuerbar über
|
||||||
|
`FACTORY_DEFAULTS_DIR`.
|
||||||
|
- Damit bringen neue VMs sofort Anbieter, Tarife, PDF-Auftragsvorlagen +
|
||||||
|
Datenschutzerklärung/Impressum mit, ohne manuelles UI-/CLI-Import.
|
||||||
|
- Bestehende Installs werden NIE überschrieben (Trigger nur wenn der
|
||||||
|
Auto-Seed im selben Start-Lauf gelaufen ist).
|
||||||
|
|
||||||
|
- [x] **📦 Factory-Defaults: HTML-Templates + Import via UI**
|
||||||
|
- Datenschutzerklärung, Impressum, Vollmacht-Vorlage und Website-Datenschutz
|
||||||
|
werden jetzt mit ins Factory-Defaults-ZIP gepackt (`app-settings/`-Ordner,
|
||||||
|
Whitelist-geschützt – andere AppSetting-Keys werden ignoriert).
|
||||||
|
- Import läuft jetzt auch über die UI (Einstellungen → Factory-Defaults →
|
||||||
|
„ZIP hochladen"). Der CLI-Weg `npm run seed:defaults` bleibt erhalten und
|
||||||
|
wurde gleichermaßen um die HTML-Templates erweitert.
|
||||||
|
- Zwei-Wege-Roundtrip live verifiziert: Export → AppSetting löschen →
|
||||||
|
Import → Wert wieder vollständig hergestellt; Counts in Audit-Log.
|
||||||
|
|
||||||
|
- [x] **🐛 Benutzer-Verwaltung: DSGVO- + Entwickler-Zugriff zuweisbar**
|
||||||
|
- Mass-Assignment-Whitelist (`pickUserUpdate`) hat `hasGdprAccess` /
|
||||||
|
`hasDeveloperAccess` rausgefiltert → Service erhielt sie nie → Rollen
|
||||||
|
DSGVO/Developer waren in der UI nicht zuweisbar (Checkbox ohne Wirkung).
|
||||||
|
- Beide Felder zur Whitelist hinzugefügt + Audit-Log liest die Pre-Werte
|
||||||
|
jetzt aus den geladenen Rollen (kein False-Positive-Change mehr).
|
||||||
|
|
||||||
|
- [x] **🔒 HTTPS-only-Header per Flag (`HTTPS_ENABLED`)**
|
||||||
|
- HSTS + `upgrade-insecure-requests` (CSP) sperrten den Browser bei
|
||||||
|
direktem `http://ip:port`-Zugriff aus (`ERR_SSL_PROTOCOL_ERROR`).
|
||||||
|
- Beide Header default OFF, kommen nur mit `HTTPS_ENABLED=true` (sobald
|
||||||
|
TLS-Reverse-Proxy davor steht).
|
||||||
|
|
||||||
|
- [x] **🗃️ Prisma-Migrations-System (statt `db push`)**
|
||||||
|
- Initial-Migration `0_init` aus aktuellem Schema generiert
|
||||||
|
(`prisma migrate diff --from-empty --to-schema-datamodel`).
|
||||||
|
- 24 alte gedriftete Migrations gelöscht – frischer Start.
|
||||||
|
- `migration_lock.toml` für MySQL hinzugefügt.
|
||||||
|
- Container-Entrypoint umgebaut:
|
||||||
|
- Auto-Baseline-Detection: bestehende DB ohne `_prisma_migrations` →
|
||||||
|
`migrate resolve --applied 0_init` läuft automatisch.
|
||||||
|
- Statt `db push --accept-data-loss` jetzt `migrate deploy` (idempotent,
|
||||||
|
datenerhaltend, keine stillen DROPs mehr).
|
||||||
|
- Neuer npm-Script `schema:sync` (lokal/Dev): legt automatisch eine
|
||||||
|
versionierte Migration mit Zeitstempel-Namen an
|
||||||
|
(`prisma migrate dev --name auto_$(date +%Y%m%d_%H%M%S)`).
|
||||||
|
- Workflow ab jetzt: schema.prisma ändern → `npm run schema:sync` →
|
||||||
|
Migration committen → Push → Container-Restart wendet sie automatisch an.
|
||||||
|
|
||||||
- [x] **🔄 Automatische Vertrags-Status-Übergänge**
|
- [x] **🔄 Automatische Vertrags-Status-Übergänge**
|
||||||
- Nightly-Cron (02:00 + Catch-up 60s nach Start): alle Verträge mit
|
- Nightly-Cron (02:00 + Catch-up 60s nach Start): alle Verträge mit
|
||||||
`status=ACTIVE` und `endDate < heute` → `EXPIRED` (mit Audit-Log).
|
`status=ACTIVE` und `endDate < heute` → `EXPIRED` (mit Audit-Log).
|
||||||
|
|||||||
Executable
+64
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Factory-Defaults-Export – holt eine ZIP vom laufenden OpenCRM und legt sie
|
||||||
|
# in ./factory-exports/ ab. Dieselbe ZIP, die du auch über die UI bekommst.
|
||||||
|
#
|
||||||
|
# Workflow:
|
||||||
|
# ./factory-export.sh # default: localhost:3010, admin@admin.com
|
||||||
|
# OPENCRM_URL=https://crm.example.de \
|
||||||
|
# OPENCRM_EMAIL=admin@example.de \
|
||||||
|
# ./factory-export.sh # gegen die Prod-Instanz
|
||||||
|
#
|
||||||
|
# Optional:
|
||||||
|
# OPENCRM_PASSWORD=… (sonst wird interaktiv abgefragt)
|
||||||
|
#
|
||||||
|
# Die ZIP ist gitignored – du kannst sie via scp transferieren und mit
|
||||||
|
# ./factory-import.sh auf der anderen Seite einspielen.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
URL="${OPENCRM_URL:-http://localhost:3010}"
|
||||||
|
EMAIL="${OPENCRM_EMAIL:-admin@admin.com}"
|
||||||
|
PASSWORD="${OPENCRM_PASSWORD:-}"
|
||||||
|
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
EXPORT_DIR="$REPO_ROOT/factory-exports"
|
||||||
|
mkdir -p "$EXPORT_DIR"
|
||||||
|
|
||||||
|
if [ -z "$PASSWORD" ]; then
|
||||||
|
read -r -s -p "Passwort für $EMAIL @ $URL: " PASSWORD
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "→ Login als $EMAIL @ $URL"
|
||||||
|
LOGIN_RESPONSE="$(curl -sS -X POST "$URL/api/auth/login" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
--data-raw "$(E="$EMAIL" P="$PASSWORD" python3 -c 'import json,os;print(json.dumps({"email":os.environ["E"],"password":os.environ["P"]}))')")"
|
||||||
|
|
||||||
|
TOKEN="$(printf '%s' "$LOGIN_RESPONSE" | python3 -c 'import json,sys;d=json.load(sys.stdin);print((d.get("data") or {}).get("token","") or d.get("token",""))')"
|
||||||
|
|
||||||
|
if [ -z "$TOKEN" ]; then
|
||||||
|
echo "✗ Login fehlgeschlagen. Antwort:"
|
||||||
|
echo "$LOGIN_RESPONSE" | head -c 500
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TIMESTAMP="$(date +%Y-%m-%d-%H%M)"
|
||||||
|
DEST="$EXPORT_DIR/factory-defaults-$TIMESTAMP.zip"
|
||||||
|
|
||||||
|
echo "→ Lade ZIP nach $DEST"
|
||||||
|
HTTP_CODE="$(curl -sS -o "$DEST" -w '%{http_code}' \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
"$URL/api/factory-defaults/export")"
|
||||||
|
|
||||||
|
if [ "$HTTP_CODE" != "200" ]; then
|
||||||
|
echo "✗ Export-Endpoint antwortete mit HTTP $HTTP_CODE"
|
||||||
|
rm -f "$DEST"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SIZE_KB="$(du -k "$DEST" | cut -f1)"
|
||||||
|
echo "✓ Export erfolgreich: $DEST (${SIZE_KB} KB)"
|
||||||
|
echo
|
||||||
|
echo "Inhalt:"
|
||||||
|
unzip -l "$DEST" | sed 's/^/ /'
|
||||||
Executable
+140
@@ -0,0 +1,140 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Factory-Defaults-Import – pflegt eine ZIP in eine OpenCRM-Instanz ein.
|
||||||
|
# Idempotent (upserts pro Kategorie, nichts wird gelöscht).
|
||||||
|
#
|
||||||
|
# Aufruf:
|
||||||
|
# ./factory-import.sh # jüngste ZIP aus factory-exports/
|
||||||
|
# ./factory-import.sh ./factory-exports/foo.zip # explizite ZIP
|
||||||
|
# ./factory-import.sh --save-as-builtin # nach Import auch ins
|
||||||
|
# ./factory-import.sh --save-as-builtin ./foo.zip # backend/factory-defaults/
|
||||||
|
# # entpacken → nächster
|
||||||
|
# # Image-Build hat sie
|
||||||
|
# # als Werkseinstellung
|
||||||
|
#
|
||||||
|
# ENV (wie factory-export.sh):
|
||||||
|
# OPENCRM_URL (default http://localhost:3010)
|
||||||
|
# OPENCRM_EMAIL (default admin@admin.com)
|
||||||
|
# OPENCRM_PASSWORD (sonst interaktiv)
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
URL="${OPENCRM_URL:-http://localhost:3010}"
|
||||||
|
EMAIL="${OPENCRM_EMAIL:-admin@admin.com}"
|
||||||
|
PASSWORD="${OPENCRM_PASSWORD:-}"
|
||||||
|
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
EXPORT_DIR="$REPO_ROOT/factory-exports"
|
||||||
|
BUILTIN_DIR="$REPO_ROOT/backend/factory-defaults"
|
||||||
|
|
||||||
|
# Argumente parsen: erlaubt sind --save-as-builtin und 0/1 ZIP-Pfade in
|
||||||
|
# beliebiger Reihenfolge.
|
||||||
|
SAVE_AS_BUILTIN=false
|
||||||
|
ZIP_PATH=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--save-as-builtin) SAVE_AS_BUILTIN=true ;;
|
||||||
|
-h|--help)
|
||||||
|
sed -n '2,16p' "$0" | sed 's/^# \?//'
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--*) echo "✗ Unbekanntes Flag: $arg"; exit 2 ;;
|
||||||
|
*)
|
||||||
|
if [ -n "$ZIP_PATH" ]; then
|
||||||
|
echo "✗ Mehrere ZIP-Pfade angegeben (nur einer erlaubt)"; exit 2
|
||||||
|
fi
|
||||||
|
ZIP_PATH="$arg"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$ZIP_PATH" ]; then
|
||||||
|
# Jüngste ZIP automatisch wählen
|
||||||
|
ZIP_PATH="$(ls -1t "$EXPORT_DIR"/*.zip 2>/dev/null | head -1 || true)"
|
||||||
|
if [ -z "$ZIP_PATH" ]; then
|
||||||
|
echo "✗ Keine ZIP angegeben und keine in $EXPORT_DIR/ gefunden."
|
||||||
|
echo " Aufruf: ./factory-import.sh <pfad/zur/factory-defaults.zip>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "→ Keine ZIP angegeben – nehme jüngste aus $EXPORT_DIR/:"
|
||||||
|
echo " $(basename "$ZIP_PATH")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$ZIP_PATH" ]; then
|
||||||
|
echo "✗ Datei nicht gefunden: $ZIP_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PASSWORD" ]; then
|
||||||
|
read -r -s -p "Passwort für $EMAIL @ $URL: " PASSWORD
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "→ Login als $EMAIL @ $URL"
|
||||||
|
LOGIN_RESPONSE="$(curl -sS -X POST "$URL/api/auth/login" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
--data-raw "$(E="$EMAIL" P="$PASSWORD" python3 -c 'import json,os;print(json.dumps({"email":os.environ["E"],"password":os.environ["P"]}))')")"
|
||||||
|
|
||||||
|
TOKEN="$(printf '%s' "$LOGIN_RESPONSE" | python3 -c 'import json,sys;d=json.load(sys.stdin);print((d.get("data") or {}).get("token","") or d.get("token",""))')"
|
||||||
|
|
||||||
|
if [ -z "$TOKEN" ]; then
|
||||||
|
echo "✗ Login fehlgeschlagen. Antwort:"
|
||||||
|
echo "$LOGIN_RESPONSE" | head -c 500
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "→ Upload + Import: $(basename "$ZIP_PATH")"
|
||||||
|
RESPONSE="$(curl -sS -X POST "$URL/api/factory-defaults/import" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "zip=@$ZIP_PATH")"
|
||||||
|
|
||||||
|
# Hübsch ausgeben + auf success prüfen
|
||||||
|
if ! printf '%s' "$RESPONSE" | python3 -c '
|
||||||
|
import json, sys
|
||||||
|
r = json.load(sys.stdin)
|
||||||
|
if not r.get("success"):
|
||||||
|
print("✗ Import fehlgeschlagen:", r.get("error", "(unbekannt)"))
|
||||||
|
sys.exit(1)
|
||||||
|
d = r.get("data", {})
|
||||||
|
print("✓ Import erfolgreich:")
|
||||||
|
for label, key in [
|
||||||
|
("Anbieter", "providers"),
|
||||||
|
("Tarife", "tariffs"),
|
||||||
|
("Kündigungsfristen", "cancellationPeriods"),
|
||||||
|
("Laufzeiten", "contractDurations"),
|
||||||
|
("Vertragskategorien","contractCategories"),
|
||||||
|
("PDF-Vorlagen", "pdfTemplates"),
|
||||||
|
("HTML-Templates", "appSettings"),
|
||||||
|
]:
|
||||||
|
print(f" {label}: {d.get(key, 0)}")
|
||||||
|
skipped = d.get("pdfTemplatesSkipped", 0)
|
||||||
|
if skipped:
|
||||||
|
print(f" (PDF-Vorlagen übersprungen: {skipped})")
|
||||||
|
warnings = d.get("warnings", []) or []
|
||||||
|
if warnings:
|
||||||
|
print("Hinweise:")
|
||||||
|
for w in warnings:
|
||||||
|
print(f" - {w}")
|
||||||
|
'; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --save-as-builtin: ZIP zusätzlich in backend/factory-defaults/ entpacken,
|
||||||
|
# damit der nächste Image-Build sie als Werkseinstellung mitnimmt.
|
||||||
|
# Vorher räumen wir auf (außer README.md + .gitkeep), damit nichts Veraltetes
|
||||||
|
# liegen bleibt.
|
||||||
|
if [ "$SAVE_AS_BUILTIN" = "true" ]; then
|
||||||
|
echo
|
||||||
|
echo "→ --save-as-builtin: aktualisiere $BUILTIN_DIR/"
|
||||||
|
if [ ! -d "$BUILTIN_DIR" ]; then
|
||||||
|
mkdir -p "$BUILTIN_DIR"
|
||||||
|
fi
|
||||||
|
# Aufräumen: alles außer README.md und .gitkeep löschen
|
||||||
|
find "$BUILTIN_DIR" -mindepth 1 \
|
||||||
|
\! -name 'README.md' \! -name '.gitkeep' \
|
||||||
|
-delete
|
||||||
|
# ZIP entpacken (manifest.json kommt mit, ist aber harmlos)
|
||||||
|
unzip -q -o "$ZIP_PATH" -d "$BUILTIN_DIR"
|
||||||
|
echo "✓ Werkseinstellungen aktualisiert. Beim nächsten 'docker-compose up"
|
||||||
|
echo " --build' landen sie im Image und seeden frische DBs automatisch."
|
||||||
|
fi
|
||||||
+2
-1
@@ -5,10 +5,11 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
dist-ssr/
|
dist-ssr/
|
||||||
|
|
||||||
# Environment
|
# Environment – echte Secrets blocken, .env.example weiter mittracken
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
!.env.example
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -1514,6 +1514,26 @@ export default function ContractDetail() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// VVL = Vertragsverlängerung beim selben Anbieter (alle Daten 1:1 + Datum berechnet)
|
||||||
|
const renewalMutation = useMutation({
|
||||||
|
mutationFn: () => contractApi.createRenewal(contractId),
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data.data) {
|
||||||
|
navigate(`/contracts/${data.data.id}/edit`);
|
||||||
|
} else {
|
||||||
|
alert('VVL wurde erstellt, aber keine ID zurückgegeben');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error('VVL Fehler:', error);
|
||||||
|
alert(`Fehler beim Erstellen der VVL: ${error instanceof Error ? error.message : 'Unbekannter Fehler'}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Dropdown-Toggle für VVL
|
||||||
|
const [showFollowUpMenu, setShowFollowUpMenu] = useState(false);
|
||||||
|
const [showVvlConfirm, setShowVvlConfirm] = useState(false);
|
||||||
|
|
||||||
// Un-Snooze Mutation
|
// Un-Snooze Mutation
|
||||||
const unsnoozeMutation = useMutation({
|
const unsnoozeMutation = useMutation({
|
||||||
mutationFn: () => contractApi.snooze(contractId, {}),
|
mutationFn: () => contractApi.snooze(contractId, {}),
|
||||||
@@ -1756,14 +1776,50 @@ export default function ContractDetail() {
|
|||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
{hasPermission('contracts:create') && !c.followUpContract && (
|
{hasPermission('contracts:create') && !c.followUpContract && (
|
||||||
<Button
|
<div className="relative inline-flex">
|
||||||
variant="secondary"
|
{/* Hauptaktion: Folgevertrag anlegen */}
|
||||||
onClick={() => setShowFollowUpConfirm(true)}
|
<Button
|
||||||
disabled={followUpMutation.isPending}
|
variant="secondary"
|
||||||
>
|
onClick={() => setShowFollowUpConfirm(true)}
|
||||||
<Copy className="w-4 h-4 mr-2" />
|
disabled={followUpMutation.isPending || renewalMutation.isPending}
|
||||||
{followUpMutation.isPending ? 'Erstelle...' : 'Folgevertrag anlegen'}
|
className="!rounded-r-none !border-r-0"
|
||||||
</Button>
|
>
|
||||||
|
<Copy className="w-4 h-4 mr-2" />
|
||||||
|
{followUpMutation.isPending ? 'Erstelle...' : 'Folgevertrag anlegen'}
|
||||||
|
</Button>
|
||||||
|
{/* Dropdown-Pfeil für VVL */}
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => setShowFollowUpMenu(!showFollowUpMenu)}
|
||||||
|
disabled={followUpMutation.isPending || renewalMutation.isPending}
|
||||||
|
className="!rounded-l-none !px-2"
|
||||||
|
title="Weitere Optionen"
|
||||||
|
>
|
||||||
|
<ChevronDown className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
{showFollowUpMenu && (
|
||||||
|
<>
|
||||||
|
{/* Click-outside-Overlay */}
|
||||||
|
<div
|
||||||
|
className="fixed inset-0 z-10"
|
||||||
|
onClick={() => setShowFollowUpMenu(false)}
|
||||||
|
/>
|
||||||
|
<div className="absolute top-full right-0 mt-1 z-20 w-56 bg-white border border-gray-200 rounded-lg shadow-lg py-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setShowFollowUpMenu(false);
|
||||||
|
setShowVvlConfirm(true);
|
||||||
|
}}
|
||||||
|
className="w-full text-left px-4 py-2 text-sm hover:bg-gray-100 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Copy className="w-4 h-4 text-gray-500" />
|
||||||
|
VVL anlegen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{c.followUpContract && (
|
{c.followUpContract && (
|
||||||
<Link to={`/contracts/${c.followUpContract.id}`}>
|
<Link to={`/contracts/${c.followUpContract.id}`}>
|
||||||
@@ -3077,6 +3133,53 @@ export default function ContractDetail() {
|
|||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/* VVL Bestätigung */}
|
||||||
|
<Modal
|
||||||
|
isOpen={showVvlConfirm}
|
||||||
|
onClose={() => setShowVvlConfirm(false)}
|
||||||
|
title="Vertragsverlängerung (VVL) anlegen"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<p className="text-gray-700">
|
||||||
|
Möchten Sie eine Vertragsverlängerung für diesen Vertrag anlegen?
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Alle Daten werden 1:1 übernommen (auch Provider, Tarif, Portal-
|
||||||
|
Zugang, Preise und Vertragsdokumente). Das Startdatum wird auf
|
||||||
|
den nächsten Laufzeit-Beginn berechnet (altes Startdatum +
|
||||||
|
Vertragslaufzeit). Das <strong>Auftragsdokument</strong> wird
|
||||||
|
<strong> nicht </strong> mitkopiert – das ist die neue,
|
||||||
|
unterschriebene VVL, die Sie selbst hochladen.
|
||||||
|
</p>
|
||||||
|
{c.startDate && c.contractDuration?.description && (
|
||||||
|
<div className="text-xs text-gray-500 bg-gray-50 p-2 rounded">
|
||||||
|
Vorhersage: alter Beginn{' '}
|
||||||
|
<strong>{new Date(c.startDate).toLocaleDateString('de-DE')}</strong> +{' '}
|
||||||
|
<strong>{c.contractDuration.description}</strong>
|
||||||
|
{' = '}neuer VVL-Beginn (siehe danach im Vertrag)
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex justify-end gap-3 pt-2">
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => setShowVvlConfirm(false)}
|
||||||
|
>
|
||||||
|
Nein
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setShowVvlConfirm(false);
|
||||||
|
renewalMutation.mutate();
|
||||||
|
}}
|
||||||
|
disabled={renewalMutation.isPending}
|
||||||
|
>
|
||||||
|
{renewalMutation.isPending ? 'Erstelle...' : 'Ja, VVL anlegen'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
{/* Status-Info Modal */}
|
{/* Status-Info Modal */}
|
||||||
<StatusInfoModal isOpen={showStatusInfo} onClose={() => setShowStatusInfo(false)} />
|
<StatusInfoModal isOpen={showStatusInfo} onClose={() => setShowStatusInfo(false)} />
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import Card from '../../components/ui/Card';
|
import Card from '../../components/ui/Card';
|
||||||
import Button from '../../components/ui/Button';
|
import Button from '../../components/ui/Button';
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
Download,
|
Download,
|
||||||
|
Upload,
|
||||||
Package,
|
Package,
|
||||||
Info,
|
Info,
|
||||||
Loader2,
|
Loader2,
|
||||||
@@ -17,6 +18,7 @@ import {
|
|||||||
Calendar,
|
Calendar,
|
||||||
FileType,
|
FileType,
|
||||||
FileText,
|
FileText,
|
||||||
|
FileCode,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import api from '../../services/api';
|
import api from '../../services/api';
|
||||||
|
|
||||||
@@ -27,6 +29,19 @@ interface PreviewCounts {
|
|||||||
contractDurations: number;
|
contractDurations: number;
|
||||||
contractCategories: number;
|
contractCategories: number;
|
||||||
pdfTemplates: number;
|
pdfTemplates: number;
|
||||||
|
appSettings: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportResult {
|
||||||
|
providers: number;
|
||||||
|
tariffs: number;
|
||||||
|
cancellationPeriods: number;
|
||||||
|
contractDurations: number;
|
||||||
|
contractCategories: number;
|
||||||
|
pdfTemplates: number;
|
||||||
|
pdfTemplatesSkipped: number;
|
||||||
|
appSettings: number;
|
||||||
|
warnings: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FactoryDefaults() {
|
export default function FactoryDefaults() {
|
||||||
@@ -34,6 +49,12 @@ export default function FactoryDefaults() {
|
|||||||
const [downloadError, setDownloadError] = useState<string | null>(null);
|
const [downloadError, setDownloadError] = useState<string | null>(null);
|
||||||
const [downloadDone, setDownloadDone] = useState(false);
|
const [downloadDone, setDownloadDone] = useState(false);
|
||||||
|
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [importing, setImporting] = useState(false);
|
||||||
|
const [importError, setImportError] = useState<string | null>(null);
|
||||||
|
const [importResult, setImportResult] = useState<ImportResult | null>(null);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const { data: previewData, isLoading } = useQuery({
|
const { data: previewData, isLoading } = useQuery({
|
||||||
queryKey: ['factory-defaults-preview'],
|
queryKey: ['factory-defaults-preview'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -86,9 +107,39 @@ export default function FactoryDefaults() {
|
|||||||
{ icon: Calendar, label: 'Laufzeiten', count: counts.contractDurations, color: 'text-pink-600' },
|
{ icon: Calendar, label: 'Laufzeiten', count: counts.contractDurations, color: 'text-pink-600' },
|
||||||
{ icon: FileType, label: 'Vertragskategorien', count: counts.contractCategories, color: 'text-orange-600' },
|
{ icon: FileType, label: 'Vertragskategorien', count: counts.contractCategories, color: 'text-orange-600' },
|
||||||
{ icon: FileText, label: 'PDF-Auftragsvorlagen', count: counts.pdfTemplates, color: 'text-green-600' },
|
{ icon: FileText, label: 'PDF-Auftragsvorlagen', count: counts.pdfTemplates, color: 'text-green-600' },
|
||||||
|
{ icon: FileCode, label: 'HTML-Templates', count: counts.appSettings ?? 0, color: 'text-teal-600' },
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const handleImport = async (file: File) => {
|
||||||
|
setImporting(true);
|
||||||
|
setImportError(null);
|
||||||
|
setImportResult(null);
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('zip', file);
|
||||||
|
const res = await api.post<{ success: boolean; data: ImportResult; error?: string }>(
|
||||||
|
'/factory-defaults/import',
|
||||||
|
formData,
|
||||||
|
{ headers: { 'Content-Type': 'multipart/form-data' } },
|
||||||
|
);
|
||||||
|
if (!res.data.success) {
|
||||||
|
throw new Error(res.data.error || 'Fehler beim Import');
|
||||||
|
}
|
||||||
|
setImportResult(res.data.data);
|
||||||
|
// Caches invalidieren – neue Anbieter, Tarife, Vorlagen tauchen sofort
|
||||||
|
// an anderer Stelle (Provider-Liste, Vertrag-Anlage, …) auf.
|
||||||
|
queryClient.invalidateQueries();
|
||||||
|
} catch (err: any) {
|
||||||
|
setImportError(
|
||||||
|
err?.response?.data?.error || err?.message || 'Fehler beim Import',
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setImporting(false);
|
||||||
|
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-4 mb-6">
|
<div className="flex items-center gap-4 mb-6">
|
||||||
@@ -109,14 +160,15 @@ export default function FactoryDefaults() {
|
|||||||
<div className="text-sm text-blue-900 space-y-1">
|
<div className="text-sm text-blue-900 space-y-1">
|
||||||
<p className="font-medium">Was sind Factory-Defaults?</p>
|
<p className="font-medium">Was sind Factory-Defaults?</p>
|
||||||
<p>
|
<p>
|
||||||
Das sind <strong>reine Stammdaten-Kataloge</strong> wie Anbieter, Tarife,
|
Das sind <strong>Stammdaten-Kataloge</strong> wie Anbieter, Tarife,
|
||||||
Kündigungsfristen, Vertragskategorien und PDF-Auftragsvorlagen. Du kannst sie
|
Kündigungsfristen, Vertragskategorien, PDF-Auftragsvorlagen und die
|
||||||
exportieren, um sie in anderen OpenCRM-Installationen als Startpunkt zu
|
HTML-Standardtexte (Datenschutzerklärung, Impressum, Vollmacht-Vorlage,
|
||||||
verwenden.
|
Website-Datenschutz). Du kannst sie exportieren, um sie in anderen
|
||||||
|
OpenCRM-Installationen als Startpunkt zu verwenden.
|
||||||
</p>
|
</p>
|
||||||
<p className="pt-1">
|
<p className="pt-1">
|
||||||
<strong>Nicht enthalten</strong> sind Kundendaten, Verträge, Dokumente, Emails
|
<strong>Nicht enthalten</strong> sind Kundendaten, Verträge, Dokumente, E-Mails
|
||||||
oder Einstellungen – dafür gibt es den separaten{' '}
|
oder Konfigurationen (SMTP, Secrets) – dafür gibt es den separaten{' '}
|
||||||
<Link to="/settings/database-backup" className="underline">
|
<Link to="/settings/database-backup" className="underline">
|
||||||
Datenbank-Backup
|
Datenbank-Backup
|
||||||
</Link>
|
</Link>
|
||||||
@@ -127,16 +179,10 @@ export default function FactoryDefaults() {
|
|||||||
|
|
||||||
<Card title="Export" className="mb-6">
|
<Card title="Export" className="mb-6">
|
||||||
<p className="text-sm text-gray-600 mb-4">
|
<p className="text-sm text-gray-600 mb-4">
|
||||||
Erstellt ein ZIP mit allen Kataloge-Daten + PDF-Vorlagen. Lade es herunter und
|
Erstellt ein ZIP mit allen Kataloge-Daten, PDF-Auftragsvorlagen und den
|
||||||
entpacke den Inhalt in einer anderen Installation unter{' '}
|
HTML-Standardtexten (Datenschutz / Impressum / Vollmacht). In einer anderen
|
||||||
<code className="bg-gray-100 px-1.5 py-0.5 rounded text-xs">
|
OpenCRM-Installation kannst du es dann unten unter <strong>Import</strong> wieder
|
||||||
backend/factory-defaults/
|
einspielen.
|
||||||
</code>
|
|
||||||
, dann dort{' '}
|
|
||||||
<code className="bg-gray-100 px-1.5 py-0.5 rounded text-xs">
|
|
||||||
npm run seed:defaults
|
|
||||||
</code>{' '}
|
|
||||||
ausführen.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
@@ -191,34 +237,88 @@ export default function FactoryDefaults() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="Import">
|
<Card title="Import">
|
||||||
<div className="space-y-3 text-sm text-gray-600">
|
<p className="text-sm text-gray-600 mb-4">
|
||||||
<p>
|
Lade hier eine zuvor exportierte Factory-Defaults-ZIP hoch. Bestehende Einträge
|
||||||
Der Import läuft über ein Kommandozeilen-Script – dadurch bleibt klar, was wann
|
werden anhand des Unique-Keys (Name / Code) <strong>aktualisiert</strong>, neue
|
||||||
passiert und es gibt keine ungeplanten Überschreibungen im Produktivbetrieb.
|
werden angelegt. Es wird nichts gelöscht – der Vorgang ist idempotent.
|
||||||
</p>
|
</p>
|
||||||
<ol className="list-decimal list-inside space-y-1 ml-2">
|
|
||||||
<li>
|
<input
|
||||||
ZIP in einer beliebigen Installation herunterladen und den Inhalt nach{' '}
|
ref={fileInputRef}
|
||||||
<code className="bg-gray-100 px-1.5 py-0.5 rounded text-xs">
|
type="file"
|
||||||
backend/factory-defaults/
|
accept=".zip,application/zip,application/x-zip-compressed"
|
||||||
</code>{' '}
|
className="hidden"
|
||||||
entpacken
|
onChange={(e) => {
|
||||||
</li>
|
const f = e.target.files?.[0];
|
||||||
<li>
|
if (f) handleImport(f);
|
||||||
Optional mehrere ZIPs zusammenwerfen (JSON-Dateien werden automatisch gemerged)
|
}}
|
||||||
</li>
|
/>
|
||||||
<li>
|
|
||||||
Im Backend-Ordner:{' '}
|
<div className="flex items-center gap-3">
|
||||||
<code className="bg-gray-100 px-1.5 py-0.5 rounded text-xs">
|
<Button
|
||||||
npm run seed:defaults
|
onClick={() => fileInputRef.current?.click()}
|
||||||
</code>
|
disabled={importing}
|
||||||
</li>
|
variant="secondary"
|
||||||
</ol>
|
>
|
||||||
<p className="pt-2">
|
{importing ? (
|
||||||
Das Script läuft <strong>idempotent</strong> – gleiche Einträge werden per
|
<>
|
||||||
unique-Key aktualisiert, neue hinzugefügt. Kann beliebig oft ausgeführt werden.
|
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||||
</p>
|
Import läuft…
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Upload className="w-4 h-4 mr-2" />
|
||||||
|
ZIP hochladen
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
Alternativ:{' '}
|
||||||
|
<code className="bg-gray-100 px-1.5 py-0.5 rounded">
|
||||||
|
npm run seed:defaults
|
||||||
|
</code>{' '}
|
||||||
|
im Backend
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{importResult && (
|
||||||
|
<div className="mt-4 p-3 bg-green-50 border border-green-200 rounded-lg text-sm text-green-800">
|
||||||
|
<div className="flex items-center gap-2 font-medium mb-2">
|
||||||
|
<Check className="w-4 h-4" />
|
||||||
|
Import erfolgreich
|
||||||
|
</div>
|
||||||
|
<ul className="list-disc list-inside space-y-0.5 text-xs">
|
||||||
|
<li>Anbieter: {importResult.providers}</li>
|
||||||
|
<li>Tarife: {importResult.tariffs}</li>
|
||||||
|
<li>Kündigungsfristen: {importResult.cancellationPeriods}</li>
|
||||||
|
<li>Laufzeiten: {importResult.contractDurations}</li>
|
||||||
|
<li>Vertragskategorien: {importResult.contractCategories}</li>
|
||||||
|
<li>
|
||||||
|
PDF-Vorlagen: {importResult.pdfTemplates}
|
||||||
|
{importResult.pdfTemplatesSkipped > 0 &&
|
||||||
|
` (${importResult.pdfTemplatesSkipped} übersprungen)`}
|
||||||
|
</li>
|
||||||
|
<li>HTML-Templates: {importResult.appSettings}</li>
|
||||||
|
</ul>
|
||||||
|
{importResult.warnings.length > 0 && (
|
||||||
|
<div className="mt-2 pt-2 border-t border-green-200 text-amber-700 text-xs">
|
||||||
|
<div className="font-medium mb-1">Hinweise:</div>
|
||||||
|
<ul className="list-disc list-inside space-y-0.5">
|
||||||
|
{importResult.warnings.map((w, i) => (
|
||||||
|
<li key={i}>{w}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{importError && (
|
||||||
|
<div className="mt-3 p-3 bg-red-50 border border-red-200 rounded-lg flex items-start gap-2 text-sm text-red-700">
|
||||||
|
<AlertCircle className="w-4 h-4 flex-shrink-0 mt-0.5" />
|
||||||
|
<span>{importError}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -657,6 +657,10 @@ export const contractApi = {
|
|||||||
const res = await api.post<ApiResponse<Contract>>(`/contracts/${id}/follow-up`);
|
const res = await api.post<ApiResponse<Contract>>(`/contracts/${id}/follow-up`);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
createRenewal: async (id: number) => {
|
||||||
|
const res = await api.post<ApiResponse<Contract>>(`/contracts/${id}/renewal`);
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
getPassword: async (id: number) => {
|
getPassword: async (id: number) => {
|
||||||
const res = await api.get<ApiResponse<{ password: string }>>(`/contracts/${id}/password`);
|
const res = await api.get<ApiResponse<{ password: string }>>(`/contracts/${id}/password`);
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user