Buchungskalender: Mails – Link-Pflicht und Testprotokoll nur im Test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-10-07 14:16:04 +00:00
1 parent e15486263f
commit 4553bc8e92
5 files changed
+42 -10

No files matched your search

+16 -4
View File
@@ -1,5 +1,6 @@
import { config } from '../../config.js'
import { loadTemplate } from '../mailTemplates.js'
import { customerOf } from '../siteFeatures.js'
import { sendAdminNotice, sendCustomerMail } from '../mailer.js'
import { einreihen } from '../termine/outbox.js'
import { formatTag } from './datum.js'
@@ -16,6 +17,8 @@ import { ladeEinstellungen, ladePreise, ladeUnterkunft } from './speicher.js'
* rechnung (G19: ukRechnungen-Dokument), stornoRechnung + erstattetCent + grund (G22), G21 braucht nichts.
*/
export const _aufrufe = []
/** Protokoll nur im Test (UK_TESTPROTOKOLL, setzt useTestEnv); nie Token, Werte oder Gastdaten. */
const testProtokoll = () => process.env.NODE_ENV === 'test' || process.env.UK_TESTPROTOKOLL === '1'
const LEER = '–'
const text = (v) => (typeof v === 'string' ? v.trim() : '')
@@ -81,10 +84,11 @@ async function stornoText(anfrage) {
}
export async function anGast(art, ctx, anfrage, extra = {}) {
_aufrufe.push({ an: 'gast', art, anfrageId: anfrage?.$id, extra })
if (testProtokoll()) _aufrufe.push({ an: 'gast', art, anfrageId: anfrage?.$id, hatToken: Boolean(extra?.token), grund: extra?.grund })
if (!GAST_ARTEN.includes(art)) throw new TypeError(`${String(art).slice(0, 20)} ist keine Gastmail`)
extra = extra ?? {}
const gast = anfrage?.gast ?? {}
if (art === 'G17' && (!text(extra.token) || !text(ctx?.siteKey))) throw new TypeError('Token oder siteKey für den Buchungslink fehlt')
if (!text(gast.email)) throw new TypeError('Empfänger fehlt')
const { einstellungen: e, werte } = await werteZuAnfrage(ctx, anfrage)
const values = { ...werte }
@@ -100,7 +104,6 @@ export async function anGast(art, ctx, anfrage, extra = {}) {
values.buchungs_link = `${config.publicBaseUrl}/unterkunft/${ctx?.siteKey ?? ''}/buchung/${anfrage.$id}?t=${token}`
values.nachricht_vermieter = text(anfrage.nachrichtVermieter)
blocks.nachricht = values.nachricht_vermieter !== ''
if (!token) throw new TypeError('Token für den Buchungslink fehlt')
}
if (art === 'G18') {
values.nachricht_vermieter = text(extra.text)
@@ -148,13 +151,13 @@ const portalUrl = (ctx) => `${config.publicBaseUrl}/dashboard.html#buchungen?pro
* values.an ersetzt die Adresse (Standard ctx.besitzerEmail). T22 geht an die Team-Adressen und wirft nie.
*/
export async function anVermieter(template, ctx, values = {}) {
_aufrufe.push({ an: 'vermieter', template, values })
if (testProtokoll()) _aufrufe.push({ an: 'vermieter', template, anfrageId: values?.anfrage?.$id })
const { anfrage, an, ...eigene } = values ?? {}
const vorgabe = {}
if (anfrage) {
const { werte } = await werteZuAnfrage(ctx, anfrage)
Object.assign(vorgabe, werte, {
kunde_name: text(ctx?.kundeName) || werte.firma,
kunde_name: text(ctx?.kundeName) || (await kundenName(ctx)) || werte.firma,
gast_email: text(anfrage.gast?.email) || LEER,
nachricht_gast: text(anfrage.gast?.nachricht) || LEER,
gesamt: formatEuro(anfrage.summen?.bruttoCent ?? 0),
@@ -177,3 +180,12 @@ function nurPlatzhalter(template, werte) {
const kennt = loadTemplate(template).placeholders
return Object.fromEntries(Object.entries(werte).filter(([k]) => kennt.includes(k) && k !== 'blocks'))
}
/** Name des Kunden (Vermieters) aus dem Kundendokument; Fehler beim Laden machen die Mail nicht kaputt. */
async function kundenName(ctx) {
try {
return text((await customerOf(ctx?.customerId))?.name)
} catch {
return ''
}
}
+3 -1
View File
@@ -2,9 +2,11 @@
import { UkFehler } from './fehler.js'
export const _aufrufe = []
/** Aufrufprotokoll nur im Test (UK_TESTPROTOKOLL, setzt useTestEnv); in Produktion waechst nichts. */
const testProtokoll = () => process.env.NODE_ENV === 'test' || process.env.UK_TESTPROTOKOLL === '1'
export async function erstatte(ctx, anfrage, betragCent, { now, idempotencyKey } = {}) {
_aufrufe.push({ anfrageId: anfrage?.$id, betragCent, idempotencyKey })
if (testProtokoll()) _aufrufe.push({ anfrageId: anfrage?.$id, betragCent, idempotencyKey })
if (!ctx?.einstellungen?.stripeAccountId) throw new UkFehler(409, 'online_aus')
return { erstattetCent: betragCent }
}