Files
prop-ai-hr/mobile-uni/src/services/learning.ts
T

45 lines
1.2 KiB
TypeScript

export interface LearningTopicAssignment {
source?: string | null;
status?: string | null;
scenarioName?: string | null;
}
const normalized = (value?: string | null) => value?.trim() || '';
export const selectLearningTopic = (
assignments: readonly LearningTopicAssignment[],
fallbackTopic: string
) => {
const scenarioAssignments = assignments.filter((item) =>
normalized(item.source) !== 'daily' && Boolean(normalized(item.scenarioName))
);
const selected = scenarioAssignments.find((item) => normalized(item.status) !== '已完成')
|| scenarioAssignments[0];
return normalized(selected?.scenarioName) || fallbackTopic;
};
export const buildLearningTopics = (
assignments: readonly LearningTopicAssignment[],
fallbackTopic: string,
quickQuestions: readonly string[]
) => {
const values = [
fallbackTopic,
...assignments
.filter((item) => normalized(item.source) !== 'daily')
.map((item) => normalized(item.scenarioName)),
...quickQuestions
];
const topics: string[] = [];
values.forEach((value) => {
const topic = normalized(value);
if (topic && !topics.includes(topic)) {
topics.push(topic);
}
});
return topics;
};