You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

  1. import { computed, reactive } from '@nuxtjs/composition-api'
  2. import { LabelDTO } from '@/services/application/label/labelData'
  3. import { CreateLabelCommand , UpdateLabelCommand } from '@/services/application/label/labelCommand'
  4. import { LabelApplicationService } from '@/services/application/label/labelApplicationService'
  5. export const useLabelList = (service: LabelApplicationService) => {
  6. const state = reactive({
  7. labels: [] as LabelDTO[]
  8. })
  9. const getLabelList = async(
  10. projectId: string
  11. ) => {
  12. state.labels = await service.list(projectId)
  13. }
  14. const createLabel = async(
  15. projectId: string,
  16. command: CreateLabelCommand
  17. ) => {
  18. await service.create(projectId, command)
  19. await getLabelList(projectId)
  20. }
  21. const updateLabel = async(
  22. projectId: string,
  23. command: UpdateLabelCommand
  24. ) => {
  25. await service.update(projectId, command)
  26. }
  27. const deleteLabelList = async(
  28. projectId: string,
  29. items: LabelDTO[]
  30. ) => {
  31. await service.bulkDelete(projectId, items)
  32. await getLabelList(projectId)
  33. }
  34. const findLabelById = (labelId: number) => {
  35. return state.labels.find(item => item.id === labelId)
  36. }
  37. const shortKeys = computed(() => {
  38. return Object.fromEntries(state.labels.map(item => [item.id, [item.suffixKey]]))
  39. })
  40. return {
  41. state,
  42. getLabelList,
  43. findLabelById,
  44. createLabel,
  45. updateLabel,
  46. deleteLabelList,
  47. shortKeys,
  48. }
  49. }