Files
jinshen-website/app/models/mappers/questionMapper.ts
R2m1liA 98f978484c feat: directus视图与转换函数
- views: 用于前端渲染的视图模型
- mapper: 用于视图模型转换的转换函数
- utils: 相关工具函数
2025-10-15 16:48:38 +08:00

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,
};
}