import { getPool } from './db'; export type Status = 'todo' | 'doing' | 'done'; export const STATUSES: Status[] = ['todo', 'doing', 'done']; export type Task = { id: number; title: string; status: Status; assignee: string | null; notes: string | null; created_at: Date; updated_at: Date; }; export const isStatus = (v: unknown): v is Status => typeof v === 'string' && (STATUSES as string[]).includes(v); export async function listTasks(): Promise { const { rows } = await getPool().query( 'SELECT id, title, status, assignee, notes, created_at, updated_at FROM tasks ORDER BY id' ); return rows; } export async function createTask(title: string, assignee?: string | null): Promise { const { rows } = await getPool().query( 'INSERT INTO tasks (title, assignee) VALUES ($1, $2) RETURNING *', [title.trim().slice(0, 200), assignee?.trim().slice(0, 80) || null] ); return rows[0]; } export async function moveTask(id: number, status: Status): Promise { const { rows } = await getPool().query( 'UPDATE tasks SET status = $2, updated_at = now() WHERE id = $1 RETURNING *', [id, status] ); return rows[0] ?? null; } export async function deleteTask(id: number): Promise { const r = await getPool().query('DELETE FROM tasks WHERE id = $1', [id]); return (r.rowCount ?? 0) > 0; } const x: number = "oops";