From 455ff655288d61ad75275fdff87f238d7beb8bb4 Mon Sep 17 00:00:00 2001 From: eff-kay Date: Fri, 5 Sep 2025 05:09:33 -0400 Subject: [PATCH 1/2] add groups --- app/api/groups/[id]/route.ts | 27 +++++++++++++++++++++++ app/api/groups/stats/routs.ts | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 app/api/groups/[id]/route.ts create mode 100644 app/api/groups/stats/routs.ts diff --git a/app/api/groups/[id]/route.ts b/app/api/groups/[id]/route.ts new file mode 100644 index 0000000..ea23275 --- /dev/null +++ b/app/api/groups/[id]/route.ts @@ -0,0 +1,27 @@ +import { NextResponse } from 'next/server'; +import { prisma } from '../../../../lib/prisma'; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + const user = await prisma.user.findUnique({ + where: { id }, + include: { + posts: true, // Include posts by the user + accounts: true, // Include user accounts + }, + }); + + if (!user) { + return NextResponse.json({ message: 'User not found' }, { status: 404 }); + } + + return NextResponse.json(user); + } catch (error) { + console.error('Error fetching user:', error); + return NextResponse.json({ message: 'Error fetching user' }, { status: 500 }); + } +} \ No newline at end of file diff --git a/app/api/groups/stats/routs.ts b/app/api/groups/stats/routs.ts new file mode 100644 index 0000000..1d101cd --- /dev/null +++ b/app/api/groups/stats/routs.ts @@ -0,0 +1,40 @@ +import { NextResponse } from 'next/server' +import { prisma } from '@/lib/prisma' +import { getServerSession } from 'next-auth' + +export async function GET() { + const session = await getServerSession() + + if (!session) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) + } + + try { + const totalUsers = await prisma.user.count() + const activeUsers = await prisma.session.count({ + where: { + expires: { + gt: new Date() + } + } + }) + + const recentUsers = await prisma.user.count({ + where: { + createdAt: { + gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // Last 7 days + } + } + }) + + return NextResponse.json({ + totalUsers, + activeUsers, + recentUsers, + timestamp: new Date().toISOString() + }) + } catch (error) { + console.error('Stats error:', error) + return NextResponse.json({ error: 'Failed to fetch stats' }, { status: 500 }) + } +} \ No newline at end of file From 3c568759a581720d7217cfe0b7448c6383bc4b64 Mon Sep 17 00:00:00 2001 From: eff-kay Date: Fri, 5 Sep 2025 05:11:07 -0400 Subject: [PATCH 2/2] add teams --- app/api/teams/[id]/route.ts | 27 ++++++++++++++++++++++++ app/api/teams/stats/routs.ts | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 app/api/teams/[id]/route.ts create mode 100644 app/api/teams/stats/routs.ts diff --git a/app/api/teams/[id]/route.ts b/app/api/teams/[id]/route.ts new file mode 100644 index 0000000..ea23275 --- /dev/null +++ b/app/api/teams/[id]/route.ts @@ -0,0 +1,27 @@ +import { NextResponse } from 'next/server'; +import { prisma } from '../../../../lib/prisma'; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + const user = await prisma.user.findUnique({ + where: { id }, + include: { + posts: true, // Include posts by the user + accounts: true, // Include user accounts + }, + }); + + if (!user) { + return NextResponse.json({ message: 'User not found' }, { status: 404 }); + } + + return NextResponse.json(user); + } catch (error) { + console.error('Error fetching user:', error); + return NextResponse.json({ message: 'Error fetching user' }, { status: 500 }); + } +} \ No newline at end of file diff --git a/app/api/teams/stats/routs.ts b/app/api/teams/stats/routs.ts new file mode 100644 index 0000000..1d101cd --- /dev/null +++ b/app/api/teams/stats/routs.ts @@ -0,0 +1,40 @@ +import { NextResponse } from 'next/server' +import { prisma } from '@/lib/prisma' +import { getServerSession } from 'next-auth' + +export async function GET() { + const session = await getServerSession() + + if (!session) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) + } + + try { + const totalUsers = await prisma.user.count() + const activeUsers = await prisma.session.count({ + where: { + expires: { + gt: new Date() + } + } + }) + + const recentUsers = await prisma.user.count({ + where: { + createdAt: { + gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // Last 7 days + } + } + }) + + return NextResponse.json({ + totalUsers, + activeUsers, + recentUsers, + timestamp: new Date().toISOString() + }) + } catch (error) { + console.error('Stats error:', error) + return NextResponse.json({ error: 'Failed to fetch stats' }, { status: 500 }) + } +} \ No newline at end of file