Files
temetro/backend/src/db/schema/tasks.ts
T
Khalid Abdi 25254dd4c1 feat: org-scoped tasks backend, wire tasks page
Add the tasks table, validation, service and routes (/api/tasks with a
PATCH for partial updates / the done toggle, RBAC-gated) and the frontend
data module. The tasks board now loads, creates and toggles real data
(optimistic toggle with rollback).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 19:41:10 +03:00

41 lines
1.3 KiB
TypeScript

import {
boolean,
index,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import type { TaskPriority } from "../../types/task.js";
import { organization, user } from "./auth.js";
// One row per care-team to-do, scoped to a clinic (organization). Shared across
// the clinic (unlike notes, which are per-author). `assignee`/`due`/`patient`
// are free text to match the lightweight board UI.
export const tasks = pgTable(
"tasks",
{
id: uuid("id").primaryKey().defaultRandom(),
organizationId: text("organization_id")
.notNull()
.references(() => organization.id, { onDelete: "cascade" }),
title: text("title").notNull(),
assignee: text("assignee").notNull().default("Unassigned"),
due: text("due").notNull().default("No due date"),
priority: text("priority").$type<TaskPriority>().notNull(),
patient: text("patient"),
notes: text("notes"),
done: boolean("done").notNull().default(false),
createdBy: text("created_by").references(() => user.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
},
(t) => [index("tasks_org_idx").on(t.organizationId)],
);