feat: 支持微信用户列表展示

This commit is contained in:
richarjiang
2026-04-05 20:19:08 +08:00
parent 7bce04a163
commit f8f6f17bd4
8 changed files with 508 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { auth } from '@/lib/auth'
export const dynamic = 'force-dynamic'
// GET /api/wx-users/[id] - Get single wx user with level progress
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth.api.getSession({
headers: request.headers,
})
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id } = await params
const user = await prisma.wxUser.findUnique({
where: { id },
include: {
levelProgress: {
orderBy: { completedAt: 'desc' },
include: {
level: {
select: {
id: true,
answer: true,
},
},
},
},
},
})
if (!user) {
return NextResponse.json(
{ error: 'User not found' },
{ status: 404 }
)
}
return NextResponse.json(user)
} catch (error) {
console.error('Error fetching wx user:', error)
return NextResponse.json(
{ error: 'Failed to fetch wx user' },
{ status: 500 }
)
}
}