Muster/Angebot: Vor-/Nachname aus dem Formular übernehmen
sample-request und offer-request akzeptieren first_name/last_name, bilden daraus den Anzeigenamen und legen sie in address ab (für Kuvert/Platzhalter im Muster- Workflow). „name" bleibt als Fallback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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))}`,
|
||||
`<p>Neue Musteranfrage von <strong>${clean(String(body.name))}</strong> (${email}${body.phone ? `, ${clean(String(body.phone))}` : ''})`
|
||||
await teamMail(schema, `Neue Musteranfrage: ${clean(vollName)}`,
|
||||
`<p>Neue Musteranfrage von <strong>${clean(vollName)}</strong> (${email}${body.phone ? `, ${clean(String(body.phone))}` : ''})`
|
||||
+ ` · Produkt: ${clean(String(body.product))} – im Board unter „Neu".</p>`
|
||||
+ (musterNachricht ? `<p><strong>Nachricht:</strong><br>${musterNachricht.replace(/\n/g, '<br>')}</p>` : ''));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user