Files
andon/server/api/defects.post.ts
Julien Calixte cb19b2df55 feat(defects): file a defect via a board-section modal (T5)
POST /api/defects validates the body with arktype (known section, uuid
project, non-empty trimmed verbatim) and resolves the reporter through a dev
seam (getReporter, ADR 0002) until OAuth lands. DefectForm is a DaisyUI modal
opened by a section click — pick a project, describe the problem, submit.
2026-05-27 23:53:49 +02:00

16 lines
661 B
TypeScript

import { type } from 'arktype'
import { getDb } from '../db/client'
import { createDefect } from '../db/repositories/defects'
import { DefectInput } from '../utils/defectInput'
import { getReporter } from '../utils/getReporter'
// File a defect against a board section (F2). Reporter comes from the seam,
// not the client; the timestamp defaults in the DB.
export default defineEventHandler(async (event) => {
const input = DefectInput(await readBody(event))
if (input instanceof type.errors) {
throw createError({ statusCode: 400, statusMessage: input.summary })
}
return createDefect(getDb(), { ...input, reporterEmail: getReporter(event) })
})