feat(projects): list + create API and creatable ProjectAutocomplete (T4)

- GET /api/projects returns the shared global list; POST /api/projects
  creates a project, deduped case-insensitively (F3).
- Repository find-or-create trims and matches on lower(name); a unique index
  on lower(name) enforces the same rule at the DB (replacing the case-
  sensitive column unique constraint) — migration 0001.
- ProjectAutocomplete: creatable autocomplete that lists projects, offers to
  create an unknown name inline, and selects it without reload.
- Integration test (dedupe/list against Postgres) + component test.
This commit is contained in:
Julien Calixte
2026-05-27 23:28:03 +02:00
parent 63f83d316a
commit 1194edcf75
11 changed files with 585 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
import { getDb } from '../db/client'
import { listProjects } from '../db/repositories/projects'
// The shared, global project list (F3).
export default defineEventHandler(async () => {
return listProjects(getDb())
})

View File

@@ -0,0 +1,12 @@
import { getDb } from '../db/client'
import { createProject } from '../db/repositories/projects'
// Create a project (case-insensitively deduped) and return it (F3).
export default defineEventHandler(async (event) => {
const body = await readBody<{ name?: unknown }>(event)
const name = typeof body?.name === 'string' ? body.name.trim() : ''
if (!name) {
throw createError({ statusCode: 400, statusMessage: 'Project name is required' })
}
return createProject(getDb(), name)
})