19 lines
452 B
TypeScript
19 lines
452 B
TypeScript
/**
|
|
* 将 Directus 返回的 Question 数据转换为 QuestionView 视图模型
|
|
*
|
|
* @param raw: 原始的 Question 数据
|
|
* @returns 转换后的 QuestionView 对象
|
|
*
|
|
* @example
|
|
* const view = toQuestionView(rawQuestion);
|
|
*/
|
|
export function toQuestionView(raw: Question): QuestionView {
|
|
const trans = raw.translations?.[0] ?? { title: '', content: '' };
|
|
|
|
return {
|
|
id: raw.id,
|
|
title: trans.title,
|
|
content: trans.content,
|
|
};
|
|
}
|