Update participant and study API routes

This commit is contained in:
2024-09-25 22:13:29 -04:00
parent 33d36007c8
commit ccc3423953
36 changed files with 1448 additions and 228 deletions

View File

@@ -0,0 +1,25 @@
import { db } from "~/server/db";
import { participants } from "~/server/db/schema";
import { NextResponse } from "next/server";
import { eq } from "drizzle-orm";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const studyId = searchParams.get('studyId');
if (!studyId) {
return NextResponse.json({ error: 'Study ID is required' }, { status: 400 });
}
const allParticipants = await db.select().from(participants).where(eq(participants.studyId, parseInt(studyId)));
return NextResponse.json(allParticipants);
}
export async function POST(request: Request) {
const { name, studyId } = await request.json();
if (!name || !studyId) {
return NextResponse.json({ error: 'Name and Study ID are required' }, { status: 400 });
}
const newParticipant = await db.insert(participants).values({ name, studyId }).returning();
return NextResponse.json(newParticipant[0]);
}