feat: directus视图与转换函数
- views: 用于前端渲染的视图模型 - mapper: 用于视图模型转换的转换函数 - utils: 相关工具函数
This commit is contained in:
18
app/models/mappers/questionMapper.ts
Normal file
18
app/models/mappers/questionMapper.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 将 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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user