diff --git a/app/composables/directus/useDocumentList.ts b/app/composables/directus/useDocumentList.ts index fc21823..11b0978 100644 --- a/app/composables/directus/useDocumentList.ts +++ b/app/composables/directus/useDocumentList.ts @@ -1,4 +1,4 @@ -import { readItems } from '@directus/sdk'; +import GetDocumentList from '@/graphql/documentList.graphql?raw'; export const useDocumentList = () => { const { $directus } = useNuxtApp(); @@ -6,62 +6,11 @@ export const useDocumentList = () => { const locale = getDirectusLocale(); return useAsyncData(`document-list-${locale}`, async () => { - return await $directus.request( - readItems('product_documents', { - fields: [ - 'id', - { - file: ['id', 'filesize', 'filename_download'], - }, - { - translations: ['id', 'title'], - }, - { - products: [ - 'id', - { - products_id: [ - 'id', - { - translations: ['id', 'name'], - }, - { - product_type: [ - 'id', - { - translations: ['id', 'name'], - }, - ], - }, - ], - }, - ], - }, - ], - deep: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - products: { - products_id: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - product_type: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - }, - }, - }, - }) + return await $directus.query<{ product_documents: ProductDocument[] }>( + GetDocumentList, + { + locale: locale, + } ); }); }; diff --git a/app/graphql/documentList.graphql b/app/graphql/documentList.graphql new file mode 100644 index 0000000..e133dcd --- /dev/null +++ b/app/graphql/documentList.graphql @@ -0,0 +1,31 @@ +query GetDocumentList($locale: String!) { + product_documents { + id + file { + id + filesize + filename_download + } + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + title + } + products { + id + products_id { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + product_type { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + } + } + } + } +} diff --git a/app/pages/support/documents.vue b/app/pages/support/documents.vue index 3320a67..454caaf 100644 --- a/app/pages/support/documents.vue +++ b/app/pages/support/documents.vue @@ -38,7 +38,9 @@ const { data, pending, error } = await useDocumentList(); const documents = computed( - () => data?.value.map((item) => toDocumentListView(item)) ?? [] + () => + data?.value.product_documents.map((item) => toDocumentListView(item)) ?? + [] ); const productTypeOptions = computed(() => {