Files
jinshen-website/server/mappers/solutionMapper.ts
R2m1liA 63c3e2e364 refactor: 重构解决方案相关Mapper
- 空值处理与类型控制:为关系型字段添加空值处理与类型控制逻辑
- 目录结构调整:分离SolutionList与Solution相关的Mapper为不同的文件
2025-12-04 17:40:04 +08:00

23 lines
528 B
TypeScript

/**
* 将 Directus 返回的 Solution 数据转换为 SolutionView 视图模型
*
* @param raw: 原始的 Solution 数据
* @returns 转换后的 SolutionView 对象
*
* ---
*
* @example
* const view = toSolutionView(rawSolution);
*/
export function toSolutionView(raw: Solution): SolutionView {
const trans = raw.translations?.[0];
return {
id: raw.id.toString(),
title: trans?.title ?? '',
summary: trans?.summary ?? '',
content: trans?.content ?? '',
createAt: raw?.create_at ?? '',
};
}