From 45b94374b0e21b4ff7665c810463f7d4f50e2de4 Mon Sep 17 00:00:00 2001 From: wmq Date: Mon, 3 Aug 2026 01:58:02 +0800 Subject: [PATCH] fix(dashboard): normalize legacy customer profile data --- server/src/index.js | 16 ++++++++++++++-- src/pages/dashboard/DashboardPage.tsx | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/index.js b/server/src/index.js index 57cbe2d..479a4ee 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -1127,13 +1127,24 @@ const kinds = { } function withDefaults(kind, body) { if (kind === 'customers') { + const source = body && typeof body === 'object' ? body : {} const value = { name: '', company: '', country: '', channel: 'telegram', email: '', phone: '', telegram: '', products: [], tags: [], source: 'telegram', stage: 'new', intentScore: 0, intentLevel: 'low', sentiment: 'neutral', riskLevel: 'none', valueLevel: 'D', isKey: false, ownerId: null, aiProfile: { summary: '', keyPoints: [], nextActions: [] }, - ...body, + ...source, + products: Array.isArray(source.products) ? source.products : [], + tags: Array.isArray(source.tags) ? source.tags : [], + aiProfile: { + summary: '', + keyPoints: [], + nextActions: [], + ...(source.aiProfile && typeof source.aiProfile === 'object' ? source.aiProfile : {}), + keyPoints: Array.isArray(source.aiProfile?.keyPoints) ? source.aiProfile.keyPoints : [], + nextActions: Array.isArray(source.aiProfile?.nextActions) ? source.aiProfile.nextActions : [], + }, } return { ...value, @@ -4493,7 +4504,8 @@ async function businessDataset(tenantId) { app.get('/api/dashboard/overview', async (req, res) => { const data = await businessDataset(req.auth.tenantId) - const { customers, conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data + const { conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data + const customers = data.customers.map((customer) => withDefaults('customers', customer)) const unread = conversations.reduce((n, x) => n + Number(x.unreadCount || 0), 0) const today = dateKey() const won = opportunities.filter((item) => item.stage === 'won').length diff --git a/src/pages/dashboard/DashboardPage.tsx b/src/pages/dashboard/DashboardPage.tsx index fb80729..b59843e 100644 --- a/src/pages/dashboard/DashboardPage.tsx +++ b/src/pages/dashboard/DashboardPage.tsx @@ -235,7 +235,7 @@ export function DashboardPage() {

- {c.products[0] ?? '—'} · 建议:{c.aiProfile.nextActions[0] ?? '跟进'} + {c.products?.[0] ?? '—'} · 建议:{c.aiProfile?.nextActions?.[0] ?? '跟进'}