From 45429a196847328d7b9940c035000a6ce758f77f Mon Sep 17 00:00:00 2001 From: Naqi Syed Date: Tue, 3 Oct 2023 10:45:34 +0500 Subject: [PATCH] chat listing and chat detail endpoints are added --- app/api/chat-listing/[childId]/route.ts | 19 +++++++++++++++++++ app/api/chat/[id]/route.ts | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 app/api/chat-listing/[childId]/route.ts create mode 100644 app/api/chat/[id]/route.ts diff --git a/app/api/chat-listing/[childId]/route.ts b/app/api/chat-listing/[childId]/route.ts new file mode 100644 index 0000000..f1be325 --- /dev/null +++ b/app/api/chat-listing/[childId]/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server" + +import { createPrisma } from "@/lib/prisma" + +// @ts-ignore +export async function GET(request: NextRequest, { params: { childId } }) { + const credentials = { + supabaseDatabaseUrl: process.env.DATABASE_URL, + } + const prisma = createPrisma({ url: credentials.supabaseDatabaseUrl }) + + const data = await prisma.chatHistory.findMany({ + where: { + childId, + }, + }) + + return NextResponse.json({ data }) +} diff --git a/app/api/chat/[id]/route.ts b/app/api/chat/[id]/route.ts new file mode 100644 index 0000000..877a4ca --- /dev/null +++ b/app/api/chat/[id]/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server" + +import { createPrisma } from "@/lib/prisma" + +// @ts-ignore +export async function GET(request: NextRequest, { params: { id } }) { + const credentials = { + supabaseDatabaseUrl: process.env.DATABASE_URL, + } + const prisma = createPrisma({ url: credentials.supabaseDatabaseUrl }) + + const data = await prisma.chatHistory.findFirst({ + where: { + id, + }, + }) + + return NextResponse.json({ data }) +}