- Next.js 14 (TS, App Router) monolith - Request entity (Draft state) via Prisma + Postgres, validated with Zod - ESLint configured - Tailwind v4 + shadcn/ui (new-york-v4 style) - Vitest test suite (6 tests, runs against throwaway Postgres DB per file) - Multi-agent dev workflow docs in CLAUDE.md and .claude/agents/
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { createRequest, listRequests, validateCreateRequestInput } from "@/lib/requests";
|
|
|
|
export async function POST(request: Request): Promise<NextResponse> {
|
|
let body: unknown;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return NextResponse.json({ error: "Request body must be valid JSON" }, { status: 400 });
|
|
}
|
|
|
|
if (typeof body !== "object" || body === null) {
|
|
return NextResponse.json({ error: "Request body must be a JSON object" }, { status: 400 });
|
|
}
|
|
|
|
const { employee_id, type, reason } = body as Record<string, unknown>;
|
|
const validation = validateCreateRequestInput({ employee_id, type, reason });
|
|
|
|
if (!validation.ok) {
|
|
return NextResponse.json({ error: validation.error }, { status: 400 });
|
|
}
|
|
|
|
const created = await createRequest(validation.value);
|
|
return NextResponse.json(created, { status: 201 });
|
|
}
|
|
|
|
export async function GET(): Promise<NextResponse> {
|
|
const requests = await listRequests();
|
|
return NextResponse.json(requests, { status: 200 });
|
|
}
|