Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/api/groups/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
40 changes: 40 additions & 0 deletions app/api/groups/stats/routs.ts
Original file line number Diff line number Diff line change
@@ -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 })
}
}
27 changes: 27 additions & 0 deletions app/api/teams/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
40 changes: 40 additions & 0 deletions app/api/teams/stats/routs.ts
Original file line number Diff line number Diff line change
@@ -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 })
}
}