feat(04-02): create GET /api/forms-library authenticated template list
- Queries form_templates ordered by name (asc)
- Returns 401 for unauthenticated requests
- Returns JSON array of { id, name, filename } for authenticated agents
This commit is contained in:
16
teressa-copeland-homes/src/app/api/forms-library/route.ts
Normal file
16
teressa-copeland-homes/src/app/api/forms-library/route.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { auth } from '@/lib/auth';
|
||||||
|
import { db } from '@/lib/db';
|
||||||
|
import { formTemplates } from '@/lib/db/schema';
|
||||||
|
import { asc } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session) return new Response('Unauthorized', { status: 401 });
|
||||||
|
|
||||||
|
const forms = await db
|
||||||
|
.select({ id: formTemplates.id, name: formTemplates.name, filename: formTemplates.filename })
|
||||||
|
.from(formTemplates)
|
||||||
|
.orderBy(asc(formTemplates.name));
|
||||||
|
|
||||||
|
return Response.json(forms);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user