feat: 文档库查询添加文档类型字段
- graphQL查询修改:添加type字段查询 - 视图模型字段更新:添加DocumentTypeView视图模型并为DocumentList类型添加type字段 - mapper更新: 添加DocumentType的转换方法
This commit is contained in:
@ -1,5 +1,31 @@
|
||||
import { isObject } from '../../server/utils/object';
|
||||
|
||||
/**
|
||||
* 将 Directus 返回的 DocumentType 数据转换为 DocumentTypeView 视图模型
|
||||
*
|
||||
* @param raw: 原始的 DocumentType 数据
|
||||
* @returns 转换后的 DocumentTypeView 对象
|
||||
*
|
||||
* @example
|
||||
* const view = toDocumentTypeView(rawDocumentType);
|
||||
*/
|
||||
export function toDocumentTypeView(
|
||||
raw: DocumentType | string | null
|
||||
): DocumentTypeView {
|
||||
if (typeof raw === 'string' || raw === null) {
|
||||
return {
|
||||
id: '-1',
|
||||
name: '',
|
||||
} satisfies DocumentTypeView;
|
||||
}
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
return {
|
||||
id: raw.id.toString(),
|
||||
name: trans?.name ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Directus 返回的 Document 数据转换为 ProductDocumentView 视图模型
|
||||
*
|
||||
@ -40,6 +66,8 @@ export function toProductDocumentView(
|
||||
export function toDocumentListView(raw: ProductDocument): DocumentListView {
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
const type = toDocumentTypeView(raw.type ?? null);
|
||||
|
||||
const file = isObject<DirectusFile>(raw.file) ? raw.file : undefined;
|
||||
const fileId = file?.id ?? '';
|
||||
|
||||
@ -73,6 +101,7 @@ export function toDocumentListView(raw: ProductDocument): DocumentListView {
|
||||
title: trans?.title ?? '',
|
||||
url: url,
|
||||
size: file?.filesize ?? 0,
|
||||
type: type,
|
||||
products: related_products,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user