feat(20-02): add clientTranscripts data layer

schema.ts: clientTranscripts table (id, lead_id/client_id nullable FKs,
title, content NOT NULL, call_date, created_at) + leadsRelations/
clientsRelations updated + clientTranscriptsRelations + TS types.

lead-service.ts: getTranscripts(leadId) — call_date DESC ordering.

actions.ts: addTranscript + deleteTranscript with requireAdmin guard,
Zod validation, and revalidatePath. TypeScript: no errors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-20 08:55:46 +02:00
parent a46e8b0bc8
commit b96b6a2083
3 changed files with 104 additions and 3 deletions
+11 -1
View File
@@ -1,6 +1,6 @@
import { eq, and, isNull, desc, gte, lte, ilike, or } from "drizzle-orm";
import { db } from "@/db";
import { leads, activities, reminders, quotes } from "@/db/schema";
import { leads, activities, reminders, quotes, clientTranscripts } from "@/db/schema";
// Get all leads
export async function getAllLeads(limit: number = 100, offset: number = 0) {
@@ -209,3 +209,13 @@ export async function getQuotesByLeadId(leadId: string) {
.where(eq(quotes.lead_id, leadId))
.orderBy(desc(quotes.created_at));
}
// Get transcript log for a lead — call_date DESC (D-05)
// Returns all fields including full content (Phase 21 reads them in bulk).
export async function getTranscripts(leadId: string) {
return await db
.select()
.from(clientTranscripts)
.where(eq(clientTranscripts.lead_id, leadId))
.orderBy(desc(clientTranscripts.call_date));
}