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.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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 (projectId: string) => {
  23. state.example = await exampleService.findById(projectId, state.example.id)
  24. }
  25. const updateProgress = async (projectId: string) => {
  26. state.progress = await app.$services.metrics.fetchMyProgress(projectId)
  27. }
  28. const confirm = async (projectId: string) => {
  29. await exampleService.confirm(projectId, state.example.id)
  30. await getExampleById(projectId)
  31. updateProgress(projectId)
  32. }
  33. return {
  34. state,
  35. confirm,
  36. getExample,
  37. updateProgress
  38. }
  39. }