feat(division): create handler for division position
This commit is contained in:
No files matched your search
@@ -66,9 +66,15 @@ const headerPrep: HeaderPrep = {
|
|||||||
minLength: 3,
|
minLength: 3,
|
||||||
debounceMs: 500,
|
debounceMs: 500,
|
||||||
showValidationFeedback: true,
|
showValidationFeedback: true,
|
||||||
onInput: (_val: string) => {},
|
onInput: (value: string) => {
|
||||||
onClick: () => {},
|
searchInput.value = value
|
||||||
onClear: () => {},
|
},
|
||||||
|
onClick: () => {
|
||||||
|
// open filter modal
|
||||||
|
},
|
||||||
|
onClear: () => {
|
||||||
|
// clear url param
|
||||||
|
},
|
||||||
},
|
},
|
||||||
addNav: {
|
addNav: {
|
||||||
label: 'Tambah',
|
label: 'Tambah',
|
||||||
@@ -82,18 +88,6 @@ const headerPrep: HeaderPrep = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const refSearchNav: RefSearchNav = {
|
|
||||||
onClick: () => {
|
|
||||||
// open filter modal
|
|
||||||
},
|
|
||||||
onInput: (_val: string) => {
|
|
||||||
// filter patient list
|
|
||||||
},
|
|
||||||
onClear: () => {
|
|
||||||
// clear url param
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
provide('rec_id', recId)
|
provide('rec_id', recId)
|
||||||
provide('rec_action', recAction)
|
provide('rec_action', recAction)
|
||||||
provide('rec_item', recItem)
|
provide('rec_item', recItem)
|
||||||
@@ -169,7 +163,7 @@ onMounted(async () => {
|
|||||||
v-model="searchInput"
|
v-model="searchInput"
|
||||||
:prep="headerPrep"
|
:prep="headerPrep"
|
||||||
@search="handleSearch"
|
@search="handleSearch"
|
||||||
:ref-search-nav="refSearchNav"
|
:ref-search-nav="headerPrep.refSearchNav"
|
||||||
class="mb-4 xl:mb-5"
|
class="mb-4 xl:mb-5"
|
||||||
/>
|
/>
|
||||||
<AppMedicineList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
<AppMedicineList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { createCrudHandler } from '~/handlers/_handler'
|
||||||
|
import { postDivisionPosition, patchDivisionPosition, removeDivisionPosition } from '~/services/division-position.service'
|
||||||
|
|
||||||
|
export const {
|
||||||
|
recId,
|
||||||
|
recAction,
|
||||||
|
recItem,
|
||||||
|
isReadonly,
|
||||||
|
isProcessing,
|
||||||
|
isFormEntryDialogOpen,
|
||||||
|
isRecordConfirmationOpen,
|
||||||
|
onResetState,
|
||||||
|
handleActionSave,
|
||||||
|
handleActionEdit,
|
||||||
|
handleActionRemove,
|
||||||
|
handleCancelForm,
|
||||||
|
} = createCrudHandler({
|
||||||
|
post: postDivisionPosition,
|
||||||
|
patch: patchDivisionPosition,
|
||||||
|
remove: removeDivisionPosition,
|
||||||
|
})
|
||||||
@@ -2,3 +2,9 @@ export interface Division {
|
|||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DivisionPosition {
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
division_id: number
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { xfetch } from '~/composables/useXfetch'
|
||||||
|
|
||||||
|
const mainUrl = '/api/v1/division-position'
|
||||||
|
|
||||||
|
export async function getDivisionPositions(params: any = null) {
|
||||||
|
try {
|
||||||
|
let url = mainUrl
|
||||||
|
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
|
||||||
|
const searchParams = new URLSearchParams()
|
||||||
|
for (const key in params) {
|
||||||
|
if (params[key] !== null && params[key] !== undefined && params[key] !== '') {
|
||||||
|
searchParams.append(key, params[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const queryString = searchParams.toString()
|
||||||
|
if (queryString) url += `?${queryString}`
|
||||||
|
}
|
||||||
|
const resp = await xfetch(mainUrl, 'GET')
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching division-positions:', error)
|
||||||
|
throw new Error('Failed to fetch division-positions')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getDivisionPositionDetail(id: number | string) {
|
||||||
|
try {
|
||||||
|
const resp = await xfetch(`${mainUrl}/${id}`, 'GET')
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching division-position detail:', error)
|
||||||
|
throw new Error('Failed to get division-position detail')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function postDivisionPosition(record: any) {
|
||||||
|
try {
|
||||||
|
const resp = await xfetch(mainUrl, 'POST', record)
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error posting division-position:', error)
|
||||||
|
throw new Error('Failed to post division-position')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function patchDivisionPosition(id: number | string, record: any) {
|
||||||
|
try {
|
||||||
|
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error putting division-position:', error)
|
||||||
|
throw new Error('Failed to put division-position')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeDivisionPosition(id: number | string) {
|
||||||
|
try {
|
||||||
|
const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE')
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting record:', error)
|
||||||
|
throw new Error('Failed to delete division-position')
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user