All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m1s
- 为SolutionType添加Sort字段用于排序 - 解决方案列表按照sort升序排序
78 lines
1.7 KiB
TypeScript
78 lines
1.7 KiB
TypeScript
/**
|
|
* 将 Directus 返回的 SolutionType 数据转换为 SolutionTypeView 视图模型
|
|
*
|
|
* @param raw: 原始的 SolutionType 数据
|
|
* @returns 转换后的 SolutionTypeView 对象
|
|
*
|
|
* ---
|
|
*
|
|
* @example
|
|
* const view = toSolutionTypeView(rawSolutionType);
|
|
*/
|
|
export function toSolutionTypeView(raw: SolutionType): SolutionTypeView {
|
|
const trans = raw.translations?.[0] ?? { name: '' };
|
|
|
|
return {
|
|
id: raw.id,
|
|
name: trans.name,
|
|
sort: raw?.sort ?? 999,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 将 Directus 返回的 Solution 数据转换为 SolutionListView 视图模型
|
|
*
|
|
* @param raw: 原始的 Solution 数据
|
|
* @returns 转换后的 SolutionListView 对象
|
|
*
|
|
* ---
|
|
*
|
|
* @example
|
|
* const view = toSolutionListView(rawSolution);
|
|
*/
|
|
export function toSolutionListView(raw: Solution): SolutionListView {
|
|
const trans = raw.translations?.[0] ?? {
|
|
title: '',
|
|
summary: '',
|
|
};
|
|
|
|
const type = isObject<SolutionType>(raw.type)
|
|
? toSolutionTypeView(raw.type)
|
|
: undefined;
|
|
|
|
return {
|
|
id: raw.id,
|
|
title: trans.title,
|
|
summary: trans.summary,
|
|
solution_type: type,
|
|
cover: isObject<DirectusFile>(raw.cover) ? raw.cover.id : raw.cover,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 将 Directus 返回的 Solution 数据转换为 SolutionView 视图模型
|
|
*
|
|
* @param raw: 原始的 Solution 数据
|
|
* @returns 转换后的 SolutionView 对象
|
|
*
|
|
* ---
|
|
*
|
|
* @example
|
|
* const view = toSolutionView(rawSolution);
|
|
*/
|
|
export function toSolutionView(raw: Solution): SolutionView {
|
|
const trans = raw.translations?.[0] ?? {
|
|
title: '',
|
|
summary: '',
|
|
content: '',
|
|
};
|
|
|
|
return {
|
|
id: raw.id,
|
|
title: trans.title,
|
|
summary: trans.summary,
|
|
content: trans.content,
|
|
createAt: raw.create_at,
|
|
};
|
|
}
|