2026-06-23 20:36:07 -04:00
|
|
|
import { redirect } from "next/navigation"
|
|
|
|
|
import { desc, eq } from "drizzle-orm"
|
|
|
|
|
import { db } from "@/lib/db"
|
|
|
|
|
import { ai_predictions } from "@/lib/db/schema"
|
|
|
|
|
import { getSessionUser } from "@/lib/session"
|
2026-07-02 13:42:34 -04:00
|
|
|
import { getEffectiveOwnerId } from "@/lib/account"
|
2026-06-23 20:36:07 -04:00
|
|
|
import { PredictionsClient } from "./predictions-client"
|
|
|
|
|
|
|
|
|
|
export const metadata = { title: "Predictive Analytics" }
|
|
|
|
|
|
|
|
|
|
export default async function PredictionsPage() {
|
|
|
|
|
const user = await getSessionUser()
|
|
|
|
|
if (!user) redirect("/login")
|
|
|
|
|
|
2026-07-02 13:42:34 -04:00
|
|
|
const ownerId = await getEffectiveOwnerId(user.id)
|
|
|
|
|
|
2026-06-23 20:36:07 -04:00
|
|
|
const predictions = await db
|
|
|
|
|
.select()
|
|
|
|
|
.from(ai_predictions)
|
2026-07-02 13:42:34 -04:00
|
|
|
.where(eq(ai_predictions.user_id, ownerId))
|
2026-06-23 20:36:07 -04:00
|
|
|
.orderBy(desc(ai_predictions.created_at))
|
|
|
|
|
|
|
|
|
|
return <PredictionsClient predictions={predictions ?? []} />
|
|
|
|
|
}
|