Browse Source

Add composition api for example

pull/1395/head
Hironsan 3 years ago
parent
commit
e8a9d29ef1
1 changed files with 45 additions and 0 deletions
  1. 45
      frontend/composables/useExampleItem.ts

45
frontend/composables/useExampleItem.ts

@ -0,0 +1,45 @@
import _ from 'lodash'
import { reactive, useContext } from '@nuxtjs/composition-api'
import { ExampleDTO } from '@/services/application/example/exampleData'
export const useExampleItem = () => {
const state = reactive({
example: {} as ExampleDTO,
totalExample: 0
})
const { app } = useContext()
const exampleService = app.$services.example
const getExample = async(
projectId: string,
filterOption: string,
{ page, q, isChecked }: { page: string, q: string, isChecked: string}
) => {
const examples = await exampleService.fetchOne(projectId, page, q, isChecked, filterOption)
state.totalExample = examples.count
if (!_.isEmpty(examples) && examples.items.length !== 0) {
state.example = examples.items[0]
}
}
const getExampleById = async(
projectId: string
) => {
state.example = await exampleService.findById(projectId, state.example.id)
}
const approve = async(
projectId: string,
) => {
const approved = !state.example.isApproved
await exampleService.approve(projectId, state.example.id, approved)
await getExampleById(projectId)
}
return {
state,
approve,
getExample,
}
}
Loading…
Cancel
Save