diff --git a/app/models/mappers/documentMapper.test.ts b/app/models/mappers/documentMapper.test.ts deleted file mode 100644 index 319ba4c..0000000 --- a/app/models/mappers/documentMapper.test.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { describe, test, expect } from 'vitest'; - -/** - * 单元测试: toProductDocumentView - */ -describe('toProductDocumentView', () => { - test('convert raw data with fileId to ProductDocumentView correctly', () => { - const rawData: ProductDocument = { - id: 1, - file: 'rand-om__-uuid-1234', - translations: [{ id: 10, title: 'Document Title' }], - }; - - expect(toProductDocumentView(rawData)).toEqual({ - id: 1, - fileId: 'rand-om__-uuid-1234', - filename: undefined, - title: 'Document Title', - url: 'http://localhost:8055/assets/rand-om__-uuid-1234', - size: undefined, - }); - }); - - test('convert raw data with fileMeta to ProductDocumentView correctly', () => { - const rawData: ProductDocument = { - id: 1, - file: { - id: 'rand-om__-uuid-1234', - filename_download: 'document.pdf', - filesize: 2048, - }, - translations: [{ id: 10, title: 'Document Title' }], - }; - - expect(toProductDocumentView(rawData)).toEqual({ - id: 1, - fileId: 'rand-om__-uuid-1234', - filename: 'document.pdf', - title: 'Document Title', - url: 'http://localhost:8055/assets/rand-om__-uuid-1234', - size: 2048, - }); - }); - - test('convert raw data with missing translations', () => { - const rawData: ProductDocument = { - id: 1, - file: 'rand-om__-uuid-1234', - translations: [], - }; - - expect(toProductDocumentView(rawData)).toEqual({ - id: 1, - fileId: 'rand-om__-uuid-1234', - filename: undefined, - title: '', - url: 'http://localhost:8055/assets/rand-om__-uuid-1234', - size: undefined, - }); - }); -}); - -/** - * 单元测试: toDocumentListView - */ -describe('toProductDocumentView', () => { - test('convert raw data with fileId to DocumentListView correctly', () => { - const rawData: ProductDocument = { - id: 1, - file: 'rand-om__-uuid-1234', - translations: [{ id: 10, title: 'Document Title' }], - products: [ - { - id: 10, - products_id: { - id: 1, - translations: [{ id: 1, name: 'Product A' }], - product_type: { - id: 1, - translations: [{ id: 1, name: 'Type A' }], - }, - }, - }, - ], - }; - - expect(toDocumentListView(rawData)).toEqual({ - id: 1, - fileId: 'rand-om__-uuid-1234', - filename: undefined, - title: 'Document Title', - url: 'http://localhost:8055/assets/rand-om__-uuid-1234', - size: undefined, - products: [ - { - id: 1, - name: 'Product A', - type: { - id: 1, - name: 'Type A', - }, - }, - ], - }); - }); -}); diff --git a/app/models/mappers/documentMapper.ts b/app/models/mappers/documentMapper.ts deleted file mode 100644 index d5c855d..0000000 --- a/app/models/mappers/documentMapper.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 将 Directus 返回的 Document 数据转换为 ProductDocumentView 视图模型 - * - * @param raw: 原始的 Document 数据 - * @returns 转换后的 ProductDocumentView 对象 - * - * @example - * const view = toProductDocumentView(rawDocument); - */ -export function toProductDocumentView( - raw: ProductDocument -): ProductDocumentView { - const trans = raw.translations?.[0] ?? { - title: '', - }; - - const fileId = typeof raw.file === 'string' ? raw.file : raw.file?.id; - const file = raw.file as DirectusFile; - - const { getFileUrl } = useDirectusFiles(); - - const url = getFileUrl(fileId); - - return { - id: raw.id, - fileId: fileId, - filename: file.filename_download, - title: trans.title, - url: url, - size: file.filesize, - }; -} - -/** - * 将 Directus 返回的 Document 数据转换为 DocumentListView 视图模型 - * - * @param raw: 原始的 Document 数据 - * @returns 转换后的 DocumentListView 对象 - * - * @example - * const view = toDocumentListView(rawDocument); - */ -export function toDocumentListView(raw: ProductDocument): DocumentListView { - const trans = raw.translations?.[0] ?? { title: '' }; - - const fileId = typeof raw.file === 'string' ? raw.file : raw.file?.id; - const file = raw.file as DirectusFile; - - const { getFileUrl } = useDirectusFiles(); - const url = getFileUrl(fileId); - - const related_products: DocumentListProduct[] = raw.products - ?.filter(isObject) - .map((item) => item.products_id) - .filter(isObject) - .map((item) => { - const productType = - isObject(item.product_type) && - ({ - id: item.product_type.id, - name: item.product_type.translations?.[0]?.name, - } satisfies DocumentListProductType); - return { - id: item.id, - name: item.translations?.[0]?.name, - type: productType, - }; - }); - - return { - id: raw.id, - fileId: fileId, - filename: file.filename_download, - title: trans.title, - url: url, - size: file.filesize, - products: related_products, - }; -} diff --git a/app/pages/about/index.vue b/app/pages/about/index.vue index 64dd05f..28a237a 100644 --- a/app/pages/about/index.vue +++ b/app/pages/about/index.vue @@ -4,7 +4,7 @@
- +
{{ $t('learn-more') }} @@ -32,9 +32,7 @@ { label: $t('navigation.home'), to: localePath('/') }, { label: $t('navigation.about-us') }, ]; - const { data, pending, error } = await useCompanyProfile(); - - const content = computed(() => toCompanyProfileView(data.value)); + const { data: companyProfile, pending, error } = await useCompanyProfile(); watch(error, (value) => { if (value) { diff --git a/app/pages/index.vue b/app/pages/index.vue index f2eb413..d9ecd28 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -1,24 +1,14 @@