Kundenansicht P5: Kundenart im Zustimmungsnachweis
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4bf1b67e67
commit
b000dba698
2 files changed
+64
-3
No files matched your search
@@ -5,6 +5,7 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { config } from '../config.js'
|
||||
import { createDocument, listDocuments, Query } from './appwriteAdmin.js'
|
||||
import { KUNDENARTEN } from './kundenart.js'
|
||||
|
||||
// Grenzen der Collection (scripts/feature-setup.mjs, FEATURE_CONSENT_ATTRIBUTES)
|
||||
const MAX_ID = 36
|
||||
@@ -74,9 +75,11 @@ export function texteHash(texte) {
|
||||
* Nachweis anfuegen. fassungen: Name => Fassung (z. B. zustimmung, leistungsbeschreibung, avv); texte: [{ id, text, haken }]
|
||||
* genau in Anzeigereihenfolge. Erlaubt leer: stripeSessionId, ip, userAgent (Nachweis der Aktivierung durch das Team) und
|
||||
* haken je Text. Wirft 400 (und schreibt nichts), wenn etwas fehlt, ungueltig oder zu lang ist.
|
||||
* kundenart (optional, 'unternehmen' | 'privat'): Kundenart zum Klickzeitpunkt (V4); das Feld wird nur geschrieben, wenn es
|
||||
* uebergeben wurde (ohne Setup-Skript kennt Appwrite es nicht), jeder andere uebergebene Wert ist ein 400.
|
||||
* @returns {Promise<object>} das angelegte Dokument
|
||||
*/
|
||||
export async function speichereZustimmung({ customerId, projectId, featureKey, stripeSessionId, fassungen, texte, ip, userAgent, konto, at } = {}) {
|
||||
export async function speichereZustimmung({ customerId, projectId, featureKey, stripeSessionId, fassungen, texte, ip, userAgent, konto, at, kundenart } = {}) {
|
||||
const daten = {
|
||||
customerId: kennung(customerId, MAX_ID, 'Kunde'),
|
||||
projectId: kennung(projectId, MAX_ID, 'Projekt'),
|
||||
@@ -90,8 +93,10 @@ export async function speichereZustimmung({ customerId, projectId, featureKey, s
|
||||
const texteJson = JSON.stringify(texte)
|
||||
if (fassungenJson.length > MAX_FASSUNGEN) throw httpError(400, 'Zustimmungsnachweis: Fassungen zu lang')
|
||||
if (texteJson.length > MAX_TEXTE) throw httpError(400, 'Zustimmungsnachweis: Texte zu lang')
|
||||
if (kundenart !== undefined && !KUNDENARTEN.includes(kundenart)) throw httpError(400, 'Zustimmungsnachweis: Kundenart ungültig')
|
||||
return createDocument(config.collections.featureConsents, {
|
||||
...daten,
|
||||
...(kundenart !== undefined ? { kundenart } : {}),
|
||||
fassungen: fassungenJson,
|
||||
texte: texteJson,
|
||||
textHash: sha256(texteJson),
|
||||
@@ -180,9 +185,10 @@ const kontoLabel = (person) => (person?.name && person?.email ? `${person.name}
|
||||
* steht nur im Log. Ohne sessionId (Gratisweg) traegt der Nachweis keine Stripe-Sitzung.
|
||||
* @param {object} req Express-Anfrage (ip, User-Agent, Sitzung)
|
||||
* @param {{ feature: object, haken?: object, customerId: string, projectId: string, sessionId?: string, klickAt: string }} p
|
||||
* feature: Registereintrag, beim Gratisweg freiweg(feature) (Zustimmung consentFrei)
|
||||
* feature: Registereintrag, beim Gratisweg freiweg(feature) (Zustimmung consentFrei), im Abo-Modell aboweg(feature)
|
||||
* kundenart (optional): Kundenart zum Klickzeitpunkt, wird nur durchgereicht, wenn sie uebergeben wurde
|
||||
*/
|
||||
export async function speichereNachweisAusAnfrage(req, { feature, haken = {}, customerId, projectId, sessionId, klickAt }) {
|
||||
export async function speichereNachweisAusAnfrage(req, { feature, haken = {}, customerId, projectId, sessionId, klickAt, kundenart }) {
|
||||
const belehrung = (await haken.belehrung?.()) ?? null
|
||||
const texte = nachweisTexte(feature, { belehrung })
|
||||
try {
|
||||
@@ -197,6 +203,7 @@ export async function speichereNachweisAusAnfrage(req, { feature, haken = {}, cu
|
||||
userAgent: req.get('user-agent'),
|
||||
konto: kontoLabel(actingPerson(req.session)),
|
||||
at: klickAt,
|
||||
...(kundenart !== undefined ? { kundenart } : {}),
|
||||
})
|
||||
} catch (err) {
|
||||
throw Object.assign(new Error(`Zustimmungsnachweis nicht gespeichert: ${err?.message}`), { status: 500, cause: err })
|
||||
|
||||
Reference in new issue
Block a user