38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
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}/` } },
|
||
],
|
||
},
|
||
},
|
||
},
|
||
],
|
||
}
|
||
}
|