fix: reports API - add DB table, rewrite routes with Drizzle, fix TipTap type errors

Added reports table to PostgreSQL and Drizzle schema. Rewrote reports API routes to use Drizzle ORM instead of PocketBase stub. Fixed shared schema to match frontend field names. Fixed TipTap v3 type errors in note-editor.tsx and report-editor.tsx (StarterKit cast+chain as any).
This commit is contained in:
Hermes
2026-08-02 02:22:31 +00:00
parent 0df6d1c1c8
commit 7297b7075e
6 changed files with 171 additions and 79 deletions
+26
View File
@@ -506,6 +506,32 @@ export const webhookDeliveries = pgTable(
// ── API Keys ─────────────────────────────────────────────────────────────────────
// ── Reports ──────────────────────────────────────────────────────────────────
export const reports = pgTable(
'reports',
{
id: uuid('id').defaultRandom().primaryKey(),
title: text('title').notNull().default('Untitled report'),
content: text('content'),
reportType: text('report_type').notNull().default('custom'),
dateRangeStart: timestamp('date_range_start', { withTimezone: true }),
dateRangeEnd: timestamp('date_range_end', { withTimezone: true }),
domain: text('domain').notNull().default('personal'),
projectId: uuid('project_id').references((): any => projects.id, { onDelete: 'set null' }),
isDraft: boolean('is_draft').default(true),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('reports_domain_idx').on(table.domain),
index('reports_type_idx').on(table.reportType),
index('reports_created_at_idx').on(table.createdAt),
]
);
export const apiKeys = pgTable(
'api_keys',
{
+9 -21
View File
@@ -27,36 +27,24 @@ export const createReportTemplateSchema = reportTemplateSchema.omit({
updated: true,
});
// ── Report Schema ────────────────────────────────────────────────────────────
// ── Report Schema (matches frontend field names) ────────────────────────────
export const reportSchema = z.object({
id: z.string(),
title: z.string().min(1, 'Report title is required'),
type: reportTypeEnum,
template_id: z.string().optional(),
domain: z.string(),
date_range: z.object({
start: z.string().datetime(),
end: z.string().datetime(),
}),
sections: z.array(z.object({
title: z.string(),
content: z.string().optional(),
data: z.record(z.unknown()).optional(),
sort_order: z.number().int().nonnegative().default(0),
})).default([]),
summary: z.string().optional(),
title: z.string().min(1, 'Report title is required').default('Untitled report'),
content: z.string().optional().default(''),
report_type: reportTypeEnum.default('custom'),
date_range_start: z.string().datetime().optional(),
date_range_end: z.string().datetime().optional(),
domain: z.string().default('personal'),
project_id: z.string().optional(),
is_draft: z.boolean().default(true),
generated_at: z.string().datetime().optional(),
tags: z.array(z.string()).default([]),
custom_fields: z.record(z.unknown()).optional(),
created: z.string().datetime(),
updated: z.string().datetime(),
});
export const createReportSchema = reportSchema.omit({
id: true,
generated_at: true,
created: true,
updated: true,
});
@@ -69,4 +57,4 @@ export type Report = z.infer<typeof reportSchema>;
export type CreateReport = z.infer<typeof createReportSchema>;
export type UpdateReport = z.infer<typeof updateReportSchema>;
export type ReportTemplate = z.infer<typeof reportTemplateSchema>;
export type CreateReportTemplate = z.infer<typeof createReportTemplateSchema>;
export type CreateReportTemplate = z.infer<typeof createReportTemplateSchema>;