This commit is contained in:
freedakgmail
2025-11-23 09:13:25 +08:00
parent 81dbf709aa
commit bade25ff26
378 changed files with 769815 additions and 2334 deletions
+42 -2
View File
@@ -3,6 +3,7 @@ import { getServerSession } from "next-auth"
import { authOptions } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import { checkPermission } from "@/lib/permissions"
import { Role } from "@prisma/client"
// 获取家族树的活动日志
export async function GET(
@@ -20,10 +21,10 @@ export async function GET(
const { searchParams } = new URL(req.url)
const limit = parseInt(searchParams.get('limit') || '50')
// 检查权限
// 检查权限(所有有权限访问该家族树的人都能查看操作日志)
const { hasPermission } = await checkPermission(session.user.id, treeId)
if (!hasPermission) {
return NextResponse.json({ error: "无权访问此家族树" }, { status: 403 })
return NextResponse.json({ error: "无权访问此家族树的操作日志" }, { status: 403 })
}
const logs = await prisma.activityLog.findMany({
@@ -50,3 +51,42 @@ export async function GET(
)
}
}
// 清空家族树的活动日志
export async function DELETE(
req: NextRequest,
{ params }: { params: Promise<{ treeId: string }> }
) {
try {
const session = await getServerSession(authOptions)
if (!session?.user?.id) {
return NextResponse.json({ error: "未授权" }, { status: 401 })
}
const { treeId } = await params
// 检查权限(需要 OWNER 权限才能清空日志)
const { hasPermission, role } = await checkPermission(session.user.id, treeId, Role.OWNER)
if (!hasPermission || role !== Role.OWNER) {
return NextResponse.json({ error: "只有家族树所有者才能清空操作日志" }, { status: 403 })
}
// 删除该家族树的所有日志
const result = await prisma.activityLog.deleteMany({
where: { treeId }
})
return NextResponse.json({
success: true,
deletedCount: result.count,
message: `已清空 ${result.count} 条操作日志`
})
} catch (error) {
console.error("清空活动日志失败:", error)
return NextResponse.json(
{ error: "清空活动日志失败" },
{ status: 500 }
)
}
}