gongxiangp2/lib/performance-survey-target-policy.ts

28 lines
960 B
TypeScript

type PerformanceSurveyTargetPolicyInput = {
requestedEmployeeIds: unknown
currentEmployeeId?: string | null
}
function normalizeEmployeeIds(value: unknown): string[] {
if (!Array.isArray(value)) return []
return Array.from(new Set(
value
.map((item) => String(item || '').trim())
.filter(Boolean),
))
}
export function getPerformanceSurveyTargetEmployeeIds({
requestedEmployeeIds,
currentEmployeeId,
}: PerformanceSurveyTargetPolicyInput): string[] {
return normalizeEmployeeIds([currentEmployeeId, ...normalizeEmployeeIds(requestedEmployeeIds)])
}
export const LEGACY_ITEM_SURVEY_DRAFT_MESSAGE = '此草稿缺少被考核人或事项名称,请重新发起调研'
export function readSurveyTargetItemName(snapshot: unknown): string | null {
if (!snapshot || typeof snapshot !== 'object' || !('itemName' in snapshot)) return null
return typeof snapshot.itemName === 'string' ? snapshot.itemName.trim() || null : null
}