Add notes API: clinic + author-scoped CRUD

New `note` table (src/db/schema/notes.ts) referencing organization + user,
with org+author scoping so a doctor only sees their own notes within the active
clinic. Adds:

- src/types/note.ts + src/lib/note-validation.ts (zod)
- src/services/notes.ts (CRUD, treats non-uuid ids as not-found)
- src/routes/notes.ts mounted at /api/notes, gated requireAuth → requireOrg
- schema barrel + generated migration drizzle/0001_*.sql (applied on startup
  by the runtime migrator)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-06-04 19:48:39 +03:00
parent 8bb341ea27
commit 7d6641ef59
10 changed files with 1698 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { z } from "zod";
// Payload accepted by POST/PUT /api/notes. `content` is editor HTML (capped to
// avoid unbounded payloads).
export const noteInputSchema = z.object({
title: z.string().trim().min(1, "Title is required.").max(200),
content: z.string().max(100_000).default(""),
});
export type NoteInput = z.infer<typeof noteInputSchema>;