Files
top-tickets/src/app/api/canned-responses/route.ts
T
Claude Sonnet 5 52ca317e9c Restore from Gitea ZIP snapshot (12.08.2026) after full instance reinstall
Git history was lost when the previous Gitea instance was wiped and
reinstalled due to an unresolved corruption bug — this commit is the
last known-good file content, exported before the reinstall. Prior
commit history is not recoverable through this path.
2026-08-12 19:24:03 +00:00

33 lines
1.0 KiB
TypeScript

export const runtime = "nodejs";
import { NextResponse } from "next/server";
import { z } from "zod";
import { requireSession } from "@/lib/auth/require";
import { listCannedResponses, createCannedResponse } from "@/lib/tickets/service";
export async function GET() {
const { session, response } = await requireSession();
if (!session) return response;
return NextResponse.json({ responses: await listCannedResponses() });
}
const createSchema = z.object({
title: z.string().min(1).max(100),
body: z.string().min(1).max(5_000),
});
export async function POST(request: Request) {
const { session, response } = await requireSession();
if (!session) return response;
const body = await request.json().catch(() => null);
const parsed = createSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json({ error: "Invalid input" }, { status: 400 });
}
const canned = await createCannedResponse(parsed.data.title, parsed.data.body);
return NextResponse.json({ response: canned }, { status: 201 });
}