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.

50 lines
1.3 KiB

  1. import _ from 'lodash'
  2. import { reactive, useContext } from '@nuxtjs/composition-api'
  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. { page, q, isChecked }: { page: string, q: string, isChecked: string}
  15. ) => {
  16. const examples = await exampleService.fetchOne(projectId, page, q, isChecked)
  17. state.totalExample = examples.count
  18. if (!_.isEmpty(examples) && examples.items.length !== 0) {
  19. state.example = examples.items[0]
  20. }
  21. }
  22. const getExampleById = async(
  23. projectId: string
  24. ) => {
  25. state.example = await exampleService.findById(projectId, state.example.id)
  26. }
  27. const updateProgress = async(projectId: string) => {
  28. state.progress = await app.$services.metrics.fetchMyProgress(projectId)
  29. }
  30. const confirm = async(
  31. projectId: string,
  32. ) => {
  33. await exampleService.confirm(projectId, state.example.id)
  34. await getExampleById(projectId)
  35. updateProgress(projectId)
  36. }
  37. return {
  38. state,
  39. confirm,
  40. getExample,
  41. updateProgress
  42. }
  43. }