gongxiangp2/lib/department-dashboard-scope.ts
2026-08-19 12:08:38 +08:00

38 lines
1.1 KiB
TypeScript
Raw Permalink 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.

const UNAVAILABLE_DEPARTMENT_SCOPE_ID = '__department_dashboard_scope_unavailable__'
function normalizeDepartmentPath(value: unknown) {
return String(value ?? '')
.split('/')
.map((part) => part.trim())
.filter(Boolean)
.join('/')
}
/**
* 部门看板只按登录人的明确部门路径取数。
*
* 不使用部门名称兜底,避免不同组织下的同名部门被合并;没有可靠路径时返回一个
* 不可能命中的员工 ID,使指标安全地显示为空,而不是扩大到个人可见或全公司范围。
*/
export function buildDepartmentDashboardEmployeeWhere(scopeDepartmentPath: unknown) {
const departmentPath = normalizeDepartmentPath(scopeDepartmentPath)
if (!departmentPath) return { id: UNAVAILABLE_DEPARTMENT_SCOPE_ID }
return {
OR: [
{ departmentPath },
{ departmentPath: { startsWith: `${departmentPath}/` } },
{
departmentMemberships: {
some: {
OR: [
{ departmentPath },
{ departmentPath: { startsWith: `${departmentPath}/` } },
],
},
},
},
],
}
}