diff --git a/extensions/directus-extension-skrift-orders/dist/index.js b/extensions/directus-extension-skrift-orders/dist/index.js index 9920d5d..121ccc3 100644 --- a/extensions/directus-extension-skrift-orders/dist/index.js +++ b/extensions/directus-extension-skrift-orders/dist/index.js @@ -1423,7 +1423,9 @@ const handler = (router, { services, getSchema, logger }) => { // ── Angebotsanfrage („Individuelles Angebot") ──────────────────────────── router.post('/offer-request', async (req, res) => { const body = req.body || {}; - const name = String(body.name || '').trim(); + const vorname = String(body.first_name || '').trim(); + const nachname = String(body.last_name || '').trim(); + const name = [vorname, nachname].filter(Boolean).join(' ') || String(body.name || '').trim(); const email = norm(body.email); const message = String(body.message || '').trim(); @@ -1456,6 +1458,7 @@ const handler = (router, { services, getSchema, logger }) => { quantity: Number.isFinite(quantity) && quantity > 0 ? quantity : null, product: body.product ? clean(String(body.product)) : null, message: clean(message), + address: (vorname || nachname) ? { first_name: clean(vorname), last_name: clean(nachname) } : null, status: 'neu', customer: customer?.id ?? null, }); @@ -1477,9 +1480,12 @@ const handler = (router, { services, getSchema, logger }) => { router.post('/sample-request', async (req, res) => { const body = req.body || {}; const email = norm(body.email); + // Vor-/Nachname getrennt; „name" bleibt als Fallback (Altstand/Kompatibilität). + const vollName = [String(body.first_name || '').trim(), String(body.last_name || '').trim()].filter(Boolean).join(' ') + || String(body.name || '').trim(); const errors = []; if (!body.product) errors.push('Produkt fehlt.'); - if (!String(body.name || '').trim()) errors.push('Name fehlt.'); + if (!vollName) errors.push('Name fehlt.'); if (!isEmail(email)) errors.push('Gültige E-Mail-Adresse fehlt.'); if (!String(body.street || '').trim() || !String(body.zip || '').trim() || !String(body.city || '').trim()) errors.push('Lieferadresse unvollständig.'); @@ -1497,12 +1503,14 @@ const handler = (router, { services, getSchema, logger }) => { await svc('offer_requests').createOne({ type: 'muster', - name: clean(String(body.name).trim()), + name: clean(vollName), email, phone: clean(String(body.phone || '').trim()) || null, product: clean(String(body.product)), message: clean(String(body.message || '').trim().slice(0, 1000)) || null, address: { + first_name: clean(String(body.first_name || '').trim()), + last_name: clean(String(body.last_name || '').trim()), street: clean(String(body.street || '')), zip: clean(String(body.zip || '')), city: clean(String(body.city || '')), @@ -1513,8 +1521,8 @@ const handler = (router, { services, getSchema, logger }) => { }); const musterNachricht = clean(String(body.message || '').trim().slice(0, 1000)); - await teamMail(schema, `Neue Musteranfrage: ${clean(String(body.name))}`, - `

Neue Musteranfrage von ${clean(String(body.name))} (${email}${body.phone ? `, ${clean(String(body.phone))}` : ''})` + await teamMail(schema, `Neue Musteranfrage: ${clean(vollName)}`, + `

Neue Musteranfrage von ${clean(vollName)} (${email}${body.phone ? `, ${clean(String(body.phone))}` : ''})` + ` · Produkt: ${clean(String(body.product))} – im Board unter „Neu".

` + (musterNachricht ? `

Nachricht:
${musterNachricht.replace(/\n/g, '
')}

` : ''));