---
phase: 20-knowledge-base-cliente
plan: "02"
status: complete
completed_at: "2026-06-20"
---

# Plan 20-02 Summary: Data Layer client_transcripts

## What Was Built

Drizzle schema, query layer e server actions per i transcript delle call.

## Key Files Modified

- `src/db/schema.ts` — tabella `clientTranscripts` + relazioni bidirezionali + TypeScript types
- `src/lib/lead-service.ts` — `getTranscripts(leadId)` con orderBy call_date DESC
- `src/app/admin/leads/actions.ts` — `addTranscript` + `deleteTranscript` con requireAdmin

## Self-Check: PASSED

- ✓ `export const clientTranscripts = pgTable("client_transcripts", ...)` in schema.ts
- ✓ `leadsRelations` aggiornato con `transcripts: many(clientTranscripts)`
- ✓ `clientsRelations` aggiornato con `transcripts: many(clientTranscripts)`
- ✓ `clientTranscriptsRelations` con one(leads) + one(clients)
- ✓ `export type ClientTranscript` e `NewClientTranscript` esportati
- ✓ `getTranscripts(leadId)` ordinato per `call_date DESC`
- ✓ `addTranscript` con requireAdmin + Zod + revalidatePath
- ✓ `deleteTranscript` con requireAdmin + revalidatePath
- ✓ `npx tsc --noEmit` → no errors
