chore: add shared handlers
This commit is contained in:
@@ -29,12 +29,11 @@ import {
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} from '~/handlers/material.handler'
|
||||
import { uoms, getUomList } from "~/handlers/_shared.handler"
|
||||
|
||||
// Services
|
||||
import { getMaterials, getMaterialDetail } from '~/services/material.service'
|
||||
import { getUoms } from '~/services/uom.service'
|
||||
|
||||
const uoms = ref<{ value: string; label: string }[]>([])
|
||||
const title = ref('')
|
||||
|
||||
const {
|
||||
@@ -93,14 +92,6 @@ const getCurrentMaterialDetail = async (id: number | string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getUomList = async () => {
|
||||
const result = await getUoms()
|
||||
if (result.success) {
|
||||
const currentUoms = result.body?.data || []
|
||||
uoms.value = currentUoms.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for row actions when recId or recAction changes
|
||||
watch([recId, recAction], () => {
|
||||
switch (recAction.value) {
|
||||
|
||||
@@ -124,12 +124,7 @@ onMounted(async () => {
|
||||
/>
|
||||
<AppInstallationList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||
|
||||
<Dialog
|
||||
v-model:open="isFormEntryDialogOpen"
|
||||
:title="!!recItem ? title : 'Tambah Instalasi'"
|
||||
size="lg"
|
||||
prevent-outside
|
||||
>
|
||||
<Dialog v-model:open="isFormEntryDialogOpen" :title="!!recItem ? title : 'Tambah Instalasi'" size="lg" prevent-outside>
|
||||
<AppInstallationEntryForm
|
||||
:schema="InstallationSchema"
|
||||
:values="recItem"
|
||||
|
||||
@@ -13,7 +13,6 @@ import { toast } from '~/components/pub/ui/toast'
|
||||
// Types
|
||||
import { ActionEvents, type HeaderPrep } from '~/components/pub/custom-ui/data/types'
|
||||
import { DeviceSchema, type DeviceFormData } from '~/schemas/device.schema'
|
||||
import type { Uom } from '~/models/uom'
|
||||
|
||||
// Handlers
|
||||
import {
|
||||
@@ -29,12 +28,11 @@ import {
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} from '~/handlers/device.handler'
|
||||
import { uoms, getUomList } from "~/handlers/_shared.handler"
|
||||
|
||||
// Services
|
||||
import { getDevices, getDeviceDetail } from '~/services/device.service'
|
||||
import { getUoms } from '~/services/uom.service'
|
||||
|
||||
const uoms = ref<{ value: string; label: string }[]>([])
|
||||
const title = ref('')
|
||||
|
||||
const {
|
||||
@@ -96,14 +94,6 @@ const getCurrentToolsDetail = async (id: number | string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getUomList = async () => {
|
||||
const result = await getUoms()
|
||||
if (result.success) {
|
||||
const currentUoms = result.body?.data || []
|
||||
uoms.value = currentUoms.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for row actions
|
||||
watch([recId, recAction], () => {
|
||||
switch (recAction.value) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// types
|
||||
import type { Uom } from '~/models/uom'
|
||||
|
||||
// services
|
||||
import { getUoms } from '~/services/uom.service'
|
||||
import { getEncounters } from '~/services/encounter.service'
|
||||
|
||||
// variables
|
||||
export const uoms = ref<{ value: string; label: string }[]>([])
|
||||
export const encounterClasses = ref<{ value: string; label: string }[]>([])
|
||||
|
||||
export const getUomList = async () => {
|
||||
const result = await getUoms()
|
||||
if (result.success) {
|
||||
const currentUoms = result.body?.data || []
|
||||
uoms.value = currentUoms.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
||||
}
|
||||
}
|
||||
|
||||
export const getEncounterClassList = async () => {
|
||||
const result = await getEncounters()
|
||||
if (result.success) {
|
||||
const currentValues = result.body?.data || []
|
||||
encounterClasses.value = currentValues.map((item: any) => ({ value: item.code || item.id, label: item.name }))
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import Error from '~/components/pub/base/error/error.vue'
|
||||
definePageMeta({
|
||||
// middleware: ['rbac'],
|
||||
roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
|
||||
title: 'List Installation',
|
||||
contentFrame: 'cf-full-width',
|
||||
title: 'Daftar Instalasi',
|
||||
contentFrame: 'cf-container-lg',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
const mainUrl = '/api/v1/encounter'
|
||||
|
||||
export async function getEncounters(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(url, 'GET')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error fetching encounters:', error)
|
||||
throw new Error('Failed to fetch encounters')
|
||||
}
|
||||
}
|
||||
|
||||
export async function getEncounterDetail(id: string | number) {
|
||||
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 encounter detail:', error)
|
||||
throw new Error('Failed to fetch encounter detail')
|
||||
}
|
||||
}
|
||||
|
||||
export async function postEncounter(data: any) {
|
||||
try {
|
||||
const resp = await xfetch(mainUrl, 'POST', data)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error creating encounter:', error)
|
||||
throw new Error('Failed to create encounter')
|
||||
}
|
||||
}
|
||||
|
||||
export async function patchEncounter(id: string | number, data: any) {
|
||||
try {
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', data)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error updating encounter:', error)
|
||||
throw new Error('Failed to update encounter')
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeEncounter(id: string | number) {
|
||||
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 encounter:', error)
|
||||
throw new Error('Failed to delete encounter')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user