gongxiangp2/scripts/debug-visibility.ts

76 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 调试部门可见素材情况
* 运行:npx tsx scripts/debug-visibility.ts
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const targetEmail = process.env.DEBUG_EMAIL || '333@qq.com';
const targetDept = process.env.DEBUG_DEPT || '视觉一部';
console.log('== 检查用户 ==');
const user = await prisma.user.findUnique({
where: { email: targetEmail },
select: {
id: true,
email: true,
username: true,
department: true,
managedDepartment: true,
role: true,
isActive: true,
isSuperAdmin: true,
},
});
console.log(user);
console.log('\n== 权限表:该部门 canView=true 的素材类型 ==');
const perms = await prisma.departmentMaterialPermission.findMany({
where: { department: targetDept, canView: true },
select: {
materialType: true,
canView: true,
canDownload: true,
canShare: true,
},
orderBy: { materialType: 'asc' },
});
console.log(perms.map((p) => p.materialType));
console.log('\n== 素材表:这些类型下的素材数量 ==');
if (perms.length > 0) {
const types = perms.map((p) => p.materialType);
const counts = await prisma.material.groupBy({
by: ['materialType'],
where: {
materialType: { in: types },
deletedAt: null,
},
_count: { _all: true },
});
console.log(counts);
} else {
console.log('无可见类型');
}
console.log('\n== Department 表 ==');
const depts = await prisma.department.findMany({
select: { name: true },
orderBy: { name: 'asc' },
});
console.log(depts.map((d) => d.name));
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});