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:
+36
-1
@@ -498,10 +498,31 @@ export const reminders = pgTable("reminders", {
|
||||
.defaultNow(),
|
||||
});
|
||||
|
||||
// ============ CLIENT TRANSCRIPTS TABLE (Knowledge Base — Phase 20) ============
|
||||
// Transcript datati delle call, multipli per lead o cliente.
|
||||
// lead_id e client_id sono entrambi nullable (D-01): un transcript può appartenere
|
||||
// a un lead pre-conversione (Phase 20 UI) o a un cliente post-conversione (futuro).
|
||||
export const clientTranscripts = pgTable("client_transcripts", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
lead_id: text("lead_id")
|
||||
.references(() => leads.id, { onDelete: "cascade" }),
|
||||
client_id: text("client_id")
|
||||
.references(() => clients.id, { onDelete: "cascade" }),
|
||||
title: text("title"),
|
||||
content: text("content").notNull(),
|
||||
call_date: text("call_date").notNull(), // "YYYY-MM-DD" — coerente con <input type="date">
|
||||
created_at: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
});
|
||||
|
||||
// ============ RELATIONS ============
|
||||
|
||||
export const clientsRelations = relations(clients, ({ many }) => ({
|
||||
projects: many(projects),
|
||||
transcripts: many(clientTranscripts),
|
||||
}));
|
||||
|
||||
export const projectsRelations = relations(projects, ({ one, many }) => ({
|
||||
@@ -632,6 +653,7 @@ export const leadsRelations = relations(leads, ({ many }) => ({
|
||||
quotes: many(quotes),
|
||||
activities: many(activities),
|
||||
reminders: many(reminders),
|
||||
transcripts: many(clientTranscripts),
|
||||
}));
|
||||
|
||||
export const activitiesRelations = relations(activities, ({ one }) => ({
|
||||
@@ -642,6 +664,17 @@ export const remindersRelations = relations(reminders, ({ one }) => ({
|
||||
lead: one(leads, { fields: [reminders.lead_id], references: [leads.id] }),
|
||||
}));
|
||||
|
||||
export const clientTranscriptsRelations = relations(clientTranscripts, ({ one }) => ({
|
||||
lead: one(leads, {
|
||||
fields: [clientTranscripts.lead_id],
|
||||
references: [leads.id],
|
||||
}),
|
||||
client: one(clients, {
|
||||
fields: [clientTranscripts.client_id],
|
||||
references: [clients.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const quotesRelations = relations(quotes, ({ one, many }) => ({
|
||||
lead: one(leads, { fields: [quotes.lead_id], references: [leads.id] }),
|
||||
client: one(clients, { fields: [quotes.client_id], references: [clients.id] }),
|
||||
@@ -704,4 +737,6 @@ export type NewLead = typeof leads.$inferInsert;
|
||||
export type Activity = typeof activities.$inferSelect;
|
||||
export type NewActivity = typeof activities.$inferInsert;
|
||||
export type Reminder = typeof reminders.$inferSelect;
|
||||
export type NewReminder = typeof reminders.$inferInsert;
|
||||
export type NewReminder = typeof reminders.$inferInsert;
|
||||
export type ClientTranscript = typeof clientTranscripts.$inferSelect;
|
||||
export type NewClientTranscript = typeof clientTranscripts.$inferInsert;
|
||||
Reference in New Issue
Block a user