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.

51 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. import { reactive, useContext } from '@nuxtjs/composition-api'
  2. import _ from 'lodash'
  3. import { ExampleDTO } from '@/services/application/example/exampleData'
  4. export const useExampleItem = () => {
  5. const state = reactive({
  6. example: {} as ExampleDTO,
  7. totalExample: 0,
  8. progress: {}
  9. })
  10. const { app } = useContext()
  11. const exampleService = app.$services.example
  12. const getExample = async (
  13. projectId: string,
  14. {
  15. page,
  16. q,
  17. isChecked,
  18. ordering
  19. }: { page: string; q: string; isChecked: string; ordering: string }
  20. ) => {
  21. const examples = await exampleService.fetchOne(projectId, page, q, isChecked, ordering)
  22. state.totalExample = examples.count
  23. if (!_.isEmpty(examples) && examples.items.length !== 0) {
  24. state.example = examples.items[0]
  25. }
  26. }
  27. const getExampleById = async (projectId: string) => {
  28. state.example = await exampleService.findById(projectId, state.example.id)
  29. }
  30. const updateProgress = async (projectId: string) => {
  31. state.progress = await app.$repositories.metrics.fetchMyProgress(projectId)
  32. }
  33. const confirm = async (projectId: string) => {
  34. await exampleService.confirm(projectId, state.example.id)
  35. await getExampleById(projectId)
  36. updateProgress(projectId)
  37. }
  38. return {
  39. state,
  40. confirm,
  41. getExample,
  42. updateProgress
  43. }
  44. }