Files
Neon-Desk/app/api/portfolio/insights/latest/route.ts

19 lines
574 B
TypeScript

import { requireAuthenticatedSession } from '@/lib/server/auth-session';
import { getStoreSnapshot } from '@/lib/server/store';
export async function GET() {
const { session, response } = await requireAuthenticatedSession();
if (response) {
return response;
}
const userId = session.user.id;
const snapshot = await getStoreSnapshot();
const insight = snapshot.insights
.filter((entry) => entry.user_id === userId)
.slice()
.sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at))[0] ?? null;
return Response.json({ insight });
}