fix(dashboard): normalize legacy customer profile data

This commit is contained in:
wmq
2026-08-03 01:58:02 +08:00
parent d585fabb7a
commit 45b94374b0
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -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