0.0.1.2
This commit is contained in:
@@ -52,7 +52,34 @@ export async function GET(
|
||||
return NextResponse.json({ error: "家族树不存在或无权访问" }, { status: 404 })
|
||||
}
|
||||
|
||||
return NextResponse.json({ tree })
|
||||
// 计算当前用户角色
|
||||
let currentUserRole = "VIEWER"
|
||||
if (tree.ownerId === session.user.id) {
|
||||
currentUserRole = "OWNER"
|
||||
} else {
|
||||
const collaborator = await prisma.treeCollaborator.findUnique({
|
||||
where: {
|
||||
treeId_userId: {
|
||||
treeId: tree.id,
|
||||
userId: session.user.id
|
||||
}
|
||||
}
|
||||
})
|
||||
if (collaborator) {
|
||||
currentUserRole = collaborator.role
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🌳 GET /api/trees/[treeId] 返回数据:', {
|
||||
treeId,
|
||||
userId: session.user.id,
|
||||
treeName: tree.name,
|
||||
currentUserRole,
|
||||
membersCount: tree._count.members,
|
||||
collaboratorsCount: tree._count.collaborators
|
||||
})
|
||||
|
||||
return NextResponse.json({ tree: { ...tree, currentUserRole } })
|
||||
} catch (error) {
|
||||
console.error("获取家族树失败:", error)
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user