Files
opencrm/backend/src/routes/customer.routes.ts
T
duffyduckandClaude Opus 4.7 57959cd782 Kunde: persönliche Du/Sie-Präferenz pro Mitarbeiter
Neue Tabelle UserCustomerSalutation (PK userId+customerId,
preference 'DU'|'SIE'). Fehlender Eintrag → Fallback auf
Customer.useInformalAddress (Kunden-Default).

Backend:
- customerService: get/set/clearSalutationPreference mit Fallback-
  Logik. Response enthält immer effektive Präferenz + `source`
  ('user' | 'customer-default'), damit die UI den Standard-Text
  anzeigen kann.
- customerController: 3 Endpunkte GET/PUT/DELETE
  /:customerId/salutation-preference. userId aus dem JWT, canAccessCustomer
  greift.

Frontend:
- customerApi: 3 neue Methoden.
- CustomerDetail: neues Feld "Anrede für mich" mit Du/Sie-Toggle
  und Zurücksetzen-Link. Wird nur Mitarbeitern angezeigt, nicht
  Portal-Usern.
- Bestehendes Feld "Anrede per" bekommt Hinweis "Standard für alle
  Mitarbeiter", damit die Semantik der beiden Felder klar ist.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-06 00:34:51 +02:00

57 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Router } from 'express';
import * as customerController from '../controllers/customer.controller.js';
import * as stressfreiEmailController from '../controllers/stressfreiEmail.controller.js';
import { authenticate, requirePermission, requireCustomerAccess } from '../middleware/auth.js';
const router = Router();
// Customers
router.get('/', authenticate, requirePermission('customers:read'), customerController.getCustomers);
router.post('/', authenticate, requirePermission('customers:create'), customerController.createCustomer);
router.get('/:id', authenticate, requireCustomerAccess, customerController.getCustomer);
router.put('/:id', authenticate, requirePermission('customers:update'), customerController.updateCustomer);
router.delete('/:id', authenticate, requirePermission('customers:delete'), customerController.deleteCustomer);
// Addresses
router.get('/:customerId/addresses', authenticate, requireCustomerAccess, customerController.getAddresses);
router.post('/:customerId/addresses', authenticate, requirePermission('customers:update'), customerController.createAddress);
// Bank Cards
router.get('/:customerId/bank-cards', authenticate, requireCustomerAccess, customerController.getBankCards);
router.post('/:customerId/bank-cards', authenticate, requirePermission('customers:update'), customerController.createBankCard);
// Identity Documents
router.get('/:customerId/documents', authenticate, requireCustomerAccess, customerController.getDocuments);
router.post('/:customerId/documents', authenticate, requirePermission('customers:update'), customerController.createDocument);
// Meters
router.get('/:customerId/meters', authenticate, requireCustomerAccess, customerController.getMeters);
router.post('/:customerId/meters', authenticate, requirePermission('customers:update'), customerController.createMeter);
// Stressfrei-Wechseln E-Mail-Adressen
router.get('/:customerId/stressfrei-emails', authenticate, requireCustomerAccess, stressfreiEmailController.getEmailsByCustomer);
router.post('/:customerId/stressfrei-emails', authenticate, requirePermission('customers:update'), stressfreiEmailController.createEmail);
// Portal Settings
router.get('/:customerId/portal', authenticate, requirePermission('customers:update'), customerController.getPortalSettings);
router.put('/:customerId/portal', authenticate, requirePermission('customers:update'), customerController.updatePortalSettings);
router.post('/:customerId/portal/password', authenticate, requirePermission('customers:update'), customerController.setPortalPassword);
router.get('/:customerId/portal/password', authenticate, requirePermission('customers:update'), customerController.getPortalPassword);
router.post('/:customerId/portal/password/generate', authenticate, requirePermission('customers:update'), customerController.generatePortalPassword);
router.post('/:customerId/portal/send-credentials', authenticate, requirePermission('customers:update'), customerController.sendPortalCredentials);
// Salutation-Präferenz pro User (Du/Sie) 2026-07-04. Nutzt
// requireCustomerAccess damit auch Portal-User (falls je nötig) nicht
// automatisch scheitern; der Endpoint speichert userId aus dem Token.
router.get('/:customerId/salutation-preference', authenticate, requireCustomerAccess, customerController.getSalutationPreference);
router.put('/:customerId/salutation-preference', authenticate, requireCustomerAccess, customerController.setSalutationPreference);
router.delete('/:customerId/salutation-preference', authenticate, requireCustomerAccess, customerController.clearSalutationPreference);
// Representatives (Vertreter)
router.get('/:customerId/representatives', authenticate, requirePermission('customers:read'), customerController.getRepresentatives);
router.post('/:customerId/representatives', authenticate, requirePermission('customers:update'), customerController.addRepresentative);
router.delete('/:customerId/representatives/:representativeId', authenticate, requirePermission('customers:update'), customerController.removeRepresentative);
router.get('/:customerId/representatives/search', authenticate, requirePermission('customers:read'), customerController.searchForRepresentative);
export default router;