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.

46 lines
1.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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 (projectId: string) => {
  10. state.labels = await service.list(projectId)
  11. }
  12. const createLabel = async (projectId: string, command: CreateLabelCommand) => {
  13. await service.create(projectId, command)
  14. await getLabelList(projectId)
  15. }
  16. const updateLabel = async (projectId: string, command: UpdateLabelCommand) => {
  17. await service.update(projectId, command)
  18. }
  19. const deleteLabelList = async (projectId: string, items: LabelDTO[]) => {
  20. await service.bulkDelete(projectId, items)
  21. await getLabelList(projectId)
  22. }
  23. const findLabelById = (labelId: number) => {
  24. return state.labels.find((item) => item.id === labelId)
  25. }
  26. const shortKeys = computed(() => {
  27. return Object.fromEntries(state.labels.map((item) => [item.id, [item.suffixKey]]))
  28. })
  29. return {
  30. state,
  31. getLabelList,
  32. findLabelById,
  33. createLabel,
  34. updateLabel,
  35. deleteLabelList,
  36. shortKeys
  37. }
  38. }