From 27b365622eaabd4189e08cfb8cf314b0c1c5733f Mon Sep 17 00:00:00 2001 From: Webklar Deploy Date: Wed, 17 Jun 2026 11:35:13 +0000 Subject: [PATCH] fix: Lead-Anlage - ungueltiges createdAt-Attribut entfernt (+temp log) Co-authored-by: Cursor --- src/lib/leads.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lib/leads.js b/src/lib/leads.js index 7007f50..9eb7bf4 100644 --- a/src/lib/leads.js +++ b/src/lib/leads.js @@ -84,15 +84,24 @@ export async function createAcquisitionTicket(customer, user) { /** Legt einen Lead an (nur Unternehmen + E-Mail) und erstellt das Akquise-Ticket. */ export async function createLead({ company, email }, user) { - const now = new Date().toISOString() - const customer = await databases.createDocument(DATABASE_ID, COLLECTIONS.CUSTOMERS, ID.unique(), { - name: company, - companyName: company, - email: email || '', - customerStatus: 'lead', - createdAt: now, - updatedAt: now, - }) + let customer + try { + customer = await databases.createDocument(DATABASE_ID, COLLECTIONS.CUSTOMERS, ID.unique(), { + name: company, + companyName: company, + email: email || '', + customerStatus: 'lead', + updatedAt: new Date().toISOString(), + }) + // #region agent log + fetch('http://127.0.0.1:7284/ingest/0747da40-b90b-4354-9b84-c9b550a81ec9', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '693b5f' }, body: JSON.stringify({ sessionId: '693b5f', runId: 'post-fix', hypothesisId: 'A', location: 'leads.js:createLead', message: 'lead created ok', data: { id: customer.$id }, timestamp: Date.now() }) }).catch(() => {}) + // #endregion + } catch (err) { + // #region agent log + fetch('http://127.0.0.1:7284/ingest/0747da40-b90b-4354-9b84-c9b550a81ec9', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '693b5f' }, body: JSON.stringify({ sessionId: '693b5f', runId: 'post-fix', hypothesisId: 'A', location: 'leads.js:createLead', message: 'lead create FAILED', data: { error: String(err && err.message) }, timestamp: Date.now() }) }).catch(() => {}) + // #endregion + throw err + } let ticket = null try { ticket = await createAcquisitionTicket(customer, user)