mirror of
https://github.com/SkalaraAI/skalara-core.git
synced 2025-04-09 23:20:15 -04:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs";
|
|
import { cookies } from "next/headers";
|
|
import { NextResponse, NextRequest } from "next/server";
|
|
import { Database } from "@/types/supabase";
|
|
import prisma from "@/lib/prisma";
|
|
|
|
async function getSession(supabase: any) {
|
|
const {
|
|
data: { session },
|
|
} = await supabase.auth.getSession();
|
|
return session;
|
|
}
|
|
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params: { taskID } }: { params: { taskID: string } }
|
|
) {
|
|
const supabase = createRouteHandlerClient<Database>({ cookies });
|
|
const session = await getSession(supabase);
|
|
|
|
if (!session) return NextResponse.redirect("/auth");
|
|
|
|
try {
|
|
const messages = await prisma.message.findMany({
|
|
where: {
|
|
task_id: BigInt(taskID),
|
|
},
|
|
orderBy: {
|
|
created_at: "asc",
|
|
},
|
|
});
|
|
|
|
console.log(messages);
|
|
|
|
const res = messages.map((message) => ({
|
|
...message,
|
|
id: String(message.id),
|
|
task_id: String(message.task_id),
|
|
}));
|
|
|
|
return NextResponse.json({ messages: res }, { status: 200 });
|
|
} catch (err) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err }, { status: 500 });
|
|
}
|
|
}
|