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.

45 lines
1.2 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. filterOption: string,
  14. { page, q, isChecked }: { page: string, q: string, isChecked: string}
  15. ) => {
  16. const examples = await exampleService.fetchOne(projectId, page, q, isChecked, filterOption)
  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 approve = async(
  28. projectId: string,
  29. ) => {
  30. const approved = !state.example.isApproved
  31. await exampleService.approve(projectId, state.example.id, approved)
  32. await getExampleById(projectId)
  33. }
  34. return {
  35. state,
  36. approve,
  37. getExample,
  38. }
  39. }