useTicketAttachments.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import QueryHandler from '#shared/server/apollo/handler/QueryHandler.ts'
  4. import { useTicketInformation } from '#desktop/pages/ticket/composables/useTicketInformation.ts'
  5. import { useTicketAttachmentsQuery } from '#desktop/pages/ticket/graphql/queries/ticketAttachments.api.ts'
  6. import type { WatchQueryFetchPolicy } from '@apollo/client/core'
  7. export const useTicketAttachments = (fetchPolicy?: WatchQueryFetchPolicy) => {
  8. const { ticketId } = useTicketInformation()
  9. const ticketAttachmentsQuery = new QueryHandler(
  10. useTicketAttachmentsQuery(
  11. () => ({
  12. ticketId: ticketId.value,
  13. }),
  14. { fetchPolicy },
  15. ),
  16. )
  17. const result = ticketAttachmentsQuery.result()
  18. const loading = ticketAttachmentsQuery.loading()
  19. const ticketAttachments = computed(() => {
  20. if (!result.value?.ticketAttachments) return []
  21. return result.value?.ticketAttachments
  22. })
  23. return {
  24. ticketAttachmentsQuery,
  25. ticketAttachments,
  26. loading,
  27. }
  28. }