Files
Holzleitner---Backend--aktu…/tool/reset_test_tour.sh
Dennis Nemec 6a9b5872e1 Backend-Arbeitsstand: ERP-Sync, Lieferlebenszyklus, Reports + config.toml
Bringt das Backend vom initialen Skeleton auf den aktuellen Arbeitsstand
(Clean Architecture: domain → application → infrastructure → api).

Wesentliche Bereiche:
- ERP-Anbindung (MSSQL-Pull der Touren, Import-Scheduler, Rückschreiben)
- Lieferlebenszyklus: Scan/Hold/Cancel/Complete, Gutschriften, Notizen,
  Bild-Anhänge, Unterschriften, PDF-Lieferreport → DOCUframe
- Stammdaten: Kunden, Artikel, Lager, Zahlungsarten, Services
- Keycloak-JWT-Gate + Fahrer-Provisionierung via Admin-API
- Admin-API-Key-Gate (X-Admin-Api-Key) für Maschinen-Endpunkte

Jüngste Änderungen dieser Session:
- Belegspezifische Kontaktdaten: alle ERP-Adressen (Beleg-/Liefer-/
  Rechnungsadresse, Ansprechpartner, Kundenstamm) mit Telefon/Mobil/
  E-Mail werden gesynct (Migration 0029, MSSQL-Query, TourDetails)
- Konfiguration von .env (envy/dotenvy) auf config.toml (toml/serde)
  umgestellt; Vorlage config.example.toml, Pfad via HOLZLEITNER_CONFIG

Nicht im Repo (per .gitignore): config.toml (Secrets), data/ (Laufzeit-/
Kundendaten), demo.mp4, .claude/, variocontrol-ai/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 17:52:58 +02:00

86 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Setzt die Smoke-Test-Touren der Accounts 1001/1002 auf einen sauberen
# Zustand für den App-Smoke-Test:
#
# * tour_date → heute (sonst filtert /me/tours/today sie weg)
# * deliveries → state='active', state_reason=NULL, assigned_car_id=NULL
# * delivery_items → scan_status='in_progress', scanned_quantity=0,
# held_reason=NULL, scan_last_updated_at=NOW()
#
# Verwendet den laufenden Postgres-Container aus docker-compose.yml. Falls
# der Container anders heißt, kann der Name per CONTAINER überschrieben
# werden:
#
# CONTAINER=hl-postgres ./tool/reset_test_tour.sh
#
# Idempotent — kann beliebig oft ausgeführt werden.
set -euo pipefail
CONTAINER="${CONTAINER:-holzleitner-postgres}"
DB_USER="${DB_USER:-holzleitner}"
DB_NAME="${DB_NAME:-holzleitner}"
ACCOUNTS="${ACCOUNTS:-1001,1002}"
if ! docker inspect "$CONTAINER" >/dev/null 2>&1; then
echo "✗ Container '$CONTAINER' läuft nicht. Starte docker compose up -d." >&2
exit 1
fi
echo "→ Reset Smoke-Test-Touren für Accounts ($ACCOUNTS) …"
docker exec -i "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" -v ON_ERROR_STOP=1 -q <<SQL
-- Tour-Datum auf heute schieben (alle Touren der Test-Accounts).
UPDATE tours
SET tour_date = CURRENT_DATE,
synced_at = NOW()
WHERE account_id IN ($ACCOUNTS);
-- Lieferungen wieder aktiv, ohne Reason, keinem Auto zugeordnet.
UPDATE deliveries
SET state = 'active',
state_reason = NULL,
assigned_car_id = NULL
WHERE tour_id IN (SELECT id FROM tours WHERE account_id IN ($ACCOUNTS));
-- Items in „nichts gescannt"-Ausgangszustand zurück.
UPDATE delivery_items
SET scan_status = 'in_progress',
scanned_quantity = 0,
held_reason = NULL,
scan_last_updated_at = NOW()
WHERE delivery_id IN (
SELECT d.id FROM deliveries d
JOIN tours t ON t.id = d.tour_id
WHERE t.account_id IN ($ACCOUNTS)
);
\\echo
\\echo --- TOUREN ---
SELECT account_id, tour_date, id FROM tours
WHERE account_id IN ($ACCOUNTS)
ORDER BY account_id, tour_date;
\\echo
\\echo --- LIEFERUNGEN ---
SELECT t.account_id, d.erp_belegnummer, d.state, d.sort_order, d.assigned_car_id
FROM deliveries d
JOIN tours t ON t.id = d.tour_id
WHERE t.account_id IN ($ACCOUNTS)
ORDER BY t.account_id, d.sort_order;
\\echo
\\echo --- ITEMS ---
SELECT t.account_id, d.erp_belegnummer, di.belegzeilen_nr,
a.name AS article, di.required_quantity, di.scan_status, di.scanned_quantity
FROM delivery_items di
JOIN deliveries d ON d.id = di.delivery_id
JOIN tours t ON t.id = d.tour_id
JOIN articles a ON a.id = di.article_id
WHERE t.account_id IN ($ACCOUNTS)
ORDER BY t.account_id, d.sort_order, di.belegzeilen_nr;
SQL
echo "✓ Reset abgeschlossen."