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.

43 lines
1.1 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. })
  9. const { app } = useContext()
  10. const exampleService = app.$services.example
  11. const getExample = async(
  12. projectId: string,
  13. { page, q, isChecked }: { page: string, q: string, isChecked: string}
  14. ) => {
  15. const examples = await exampleService.fetchOne(projectId, page, q, isChecked)
  16. state.totalExample = examples.count
  17. if (!_.isEmpty(examples) && examples.items.length !== 0) {
  18. state.example = examples.items[0]
  19. }
  20. }
  21. const getExampleById = async(
  22. projectId: string
  23. ) => {
  24. state.example = await exampleService.findById(projectId, state.example.id)
  25. }
  26. const confirm = async(
  27. projectId: string,
  28. ) => {
  29. await exampleService.confirm(projectId, state.example.id)
  30. await getExampleById(projectId)
  31. }
  32. return {
  33. state,
  34. confirm,
  35. getExample,
  36. }
  37. }