chore: modify service and hanler

This commit is contained in:
riefive
2025-09-26 14:03:44 +07:00
parent 34a4fc11d0
commit 5d41e4e60d
9 changed files with 116 additions and 62 deletions
+5 -5
View File
@@ -30,8 +30,8 @@ import {
} from '~/handlers/material.handler'
// Services
import { getSourceMaterials, getSourceMaterialDetail } from '~/services/material.service'
import { getSourceUoms } from '~/services/uom.service'
import { getMaterials, getMaterialDetail } from '~/services/material.service'
import { getUoms } from '~/services/uom.service'
const uoms = ref<{ value: string; label: string }[]>([])
const title = ref('')
@@ -46,7 +46,7 @@ const {
fetchData: getEquipmentList,
} = usePaginatedList({
fetchFn: async ({ page }) => {
const result = await getSourceMaterials({ search: searchInput.value, page })
const result = await getMaterials({ search: searchInput.value, page })
return { success: result.success || false, body: result.body || {} }
},
entityName: 'equipment',
@@ -88,7 +88,7 @@ provide('rec_item', recItem)
provide('table_data_loader', isLoading)
const getCurrentMaterialDetail = async (id: number | string) => {
const result = await getSourceMaterialDetail(id)
const result = await getMaterialDetail(id)
if (result.success) {
const currentMaterial = result.body?.data || {}
recItem.value = currentMaterial
@@ -97,7 +97,7 @@ const getCurrentMaterialDetail = async (id: number | string) => {
}
const getUomList = async () => {
const result = await getSourceUoms()
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 }))
+5 -5
View File
@@ -30,8 +30,8 @@ import {
} from '~/handlers/device.handler'
// Services
import { getSourceDevices, getSourceDeviceDetail } from '~/services/device.service'
import { getSourceUoms } from '~/services/uom.service'
import { getDevices, getDeviceDetail } from '~/services/device.service'
import { getUoms } from '~/services/uom.service'
const uoms = ref<{ value: string; label: string }[]>([])
const title = ref('')
@@ -46,7 +46,7 @@ const {
fetchData: getToolsList,
} = usePaginatedList({
fetchFn: async ({ page }) => {
const result = await getSourceDevices({ search: searchInput.value, page })
const result = await getDevices({ search: searchInput.value, page })
return { success: result.success || false, body: result.body || {} }
},
entityName: 'device',
@@ -88,7 +88,7 @@ provide('rec_item', recItem)
provide('table_data_loader', isLoading)
const getCurrentToolsDetail = async (id: number | string) => {
const result = await getSourceDeviceDetail(id)
const result = await getDeviceDetail(id)
if (result.success) {
const currentDevice = result.body?.data || {}
recItem.value = currentDevice
@@ -96,7 +96,7 @@ const getCurrentToolsDetail = async (id: number | string) => {
}
const getUomList = async () => {
const result = await getSourceUoms()
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 }))
+4 -4
View File
@@ -4,7 +4,7 @@ import { ref } from 'vue'
import { type ToastFn, handleAsyncAction } from '~/handlers/_handler'
// Services
import { postSourceDevice, patchSourceDevice, removeSourceDevice } from '~/services/device.service'
import { postDevice, patchDevice, removeDevice } from '~/services/device.service'
const recId = ref<number>(0)
const recAction = ref<string>('')
@@ -28,7 +28,7 @@ export async function handleActionSave(
) {
isProcessing.value = true;
await handleAsyncAction<[any], any>({
action: postSourceDevice,
action: postDevice,
args: [values],
toast,
successMessage: 'Data berhasil disimpan',
@@ -53,7 +53,7 @@ export async function handleActionEdit(
) {
isProcessing.value = true;
await handleAsyncAction<[number | string, any], any>({
action: patchSourceDevice,
action: patchDevice,
args: [id, values],
toast,
successMessage: 'Data berhasil diubah',
@@ -76,7 +76,7 @@ export async function handleActionRemove(
) {
isProcessing.value = true;
await handleAsyncAction<[number | string], any>({
action: removeSourceDevice,
action: removeDevice,
args: [id],
toast,
successMessage: 'Data berhasil dihapus',
+4 -4
View File
@@ -4,7 +4,7 @@ import { ref } from 'vue'
import { type ToastFn, handleAsyncAction } from '~/handlers/_handler'
// Services
import { postSourceMaterial, patchSourceMaterial, removeSourceMaterial } from '~/services/material.service'
import { postMaterial, patchMaterial, removeMaterial } from '~/services/material.service'
const recId = ref<number>(0)
const recAction = ref<string>('')
@@ -23,7 +23,7 @@ function onResetState() {
export async function handleActionSave(values: any, refresh: () => void, reset: () => void, toast: ToastFn) {
isProcessing.value = true
await handleAsyncAction<[any], any>({
action: postSourceMaterial,
action: postMaterial,
args: [values],
toast,
successMessage: 'Data berhasil disimpan',
@@ -48,7 +48,7 @@ export async function handleActionEdit(
) {
isProcessing.value = true
await handleAsyncAction<[number | string, any], any>({
action: patchSourceMaterial,
action: patchMaterial,
args: [id, values],
toast,
successMessage: 'Data berhasil diubah',
@@ -67,7 +67,7 @@ export async function handleActionEdit(
export async function handleActionRemove(id: number | string, refresh: () => void, toast: ToastFn) {
isProcessing.value = true
await handleAsyncAction<[number | string], any>({
action: removeSourceMaterial,
action: removeMaterial,
args: [id],
toast,
successMessage: 'Data berhasil dihapus',
+7 -7
View File
@@ -2,7 +2,7 @@ import { xfetch } from '~/composables/useXfetch'
const mainUrl = '/api/v1/device'
export async function getSourceDevices(params: any = null) {
export async function getDevices(params: any = null) {
try {
let url = mainUrl
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
@@ -21,12 +21,12 @@ export async function getSourceDevices(params: any = null) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source devices:', error)
throw new Error('Failed to fetch source devices')
console.error('Error fetching devices:', error)
throw new Error('Failed to fetch devices')
}
}
export async function getSourceDeviceDetail(id: string | number) {
export async function getDeviceDetail(id: string | number) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'GET')
const result: any = {}
@@ -39,7 +39,7 @@ export async function getSourceDeviceDetail(id: string | number) {
}
}
export async function postSourceDevice(data: any) {
export async function postDevice(data: any) {
try {
const resp = await xfetch(mainUrl, 'POST', data)
const result: any = {}
@@ -52,7 +52,7 @@ export async function postSourceDevice(data: any) {
}
}
export async function patchSourceDevice(id: string | number, data: any) {
export async function patchDevice(id: string | number, data: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', data)
const result: any = {}
@@ -65,7 +65,7 @@ export async function patchSourceDevice(id: string | number, data: any) {
}
}
export async function removeSourceDevice(id: string | number) {
export async function removeDevice(id: string | number) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE')
const result: any = {}
+14 -14
View File
@@ -2,7 +2,7 @@ import { xfetch } from '~/composables/useXfetch'
const mainUrl = '/api/v1/material'
export async function getSourceMaterials(params: any = null) {
export async function getMaterials(params: any = null) {
try {
let url = mainUrl
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
@@ -21,12 +21,12 @@ export async function getSourceMaterials(params: any = null) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source materials:', error)
throw new Error('Failed to fetch source materials')
console.error('Error fetching materials:', error)
throw new Error('Failed to fetch materials')
}
}
export async function getSourceMaterialDetail(id: number | string) {
export async function getMaterialDetail(id: number | string) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'GET')
const result: any = {}
@@ -34,12 +34,12 @@ export async function getSourceMaterialDetail(id: number | string) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source material detail:', error)
throw new Error('Failed to get source material detail')
console.error('Error fetching material detail:', error)
throw new Error('Failed to get material detail')
}
}
export async function postSourceMaterial(record: any) {
export async function postMaterial(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
@@ -47,12 +47,12 @@ export async function postSourceMaterial(record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting source material:', error)
throw new Error('Failed to post source material')
console.error('Error posting material:', error)
throw new Error('Failed to post material')
}
}
export async function patchSourceMaterial(id: number | string, record: any) {
export async function patchMaterial(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
@@ -60,12 +60,12 @@ export async function patchSourceMaterial(id: number | string, record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting source material:', error)
throw new Error('Failed to put source material')
console.error('Error putting material:', error)
throw new Error('Failed to put material')
}
}
export async function removeSourceMaterial(id: number | string) {
export async function removeMaterial(id: number | string) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE')
const result: any = {}
@@ -74,6 +74,6 @@ export async function removeSourceMaterial(id: number | string) {
return result
} catch (error) {
console.error('Error deleting record:', error)
throw new Error('Failed to delete source material')
throw new Error('Failed to delete material')
}
}
+9 -9
View File
@@ -21,8 +21,8 @@ export async function getMedicineGroups(params: any = null) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source materials:', error)
throw new Error('Failed to fetch source materials')
console.error('Error fetching medicine groups:', error)
throw new Error('Failed to fetch medicine groups')
}
}
@@ -34,8 +34,8 @@ export async function getMedicineGroupDetail(id: number | string) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source material detail:', error)
throw new Error('Failed to get source material detail')
console.error('Error fetching medicine group detail:', error)
throw new Error('Failed to get medicine group detail')
}
}
@@ -47,8 +47,8 @@ export async function postMedicineGroup(record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting source material:', error)
throw new Error('Failed to post source material')
console.error('Error posting medicine group:', error)
throw new Error('Failed to post medicine group')
}
}
@@ -60,8 +60,8 @@ export async function patchMedicineGroup(id: number | string, record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting source material:', error)
throw new Error('Failed to put source material')
console.error('Error putting medicine group:', error)
throw new Error('Failed to put medicine group')
}
}
@@ -74,6 +74,6 @@ export async function removeMedicineGroup(id: number | string) {
return result
} catch (error) {
console.error('Error deleting record:', error)
throw new Error('Failed to delete source material')
throw new Error('Failed to delete medicine group')
}
}
+9 -9
View File
@@ -29,8 +29,8 @@ export async function getMedicineMethods(params: any = null) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source materials:', error)
throw new Error('Failed to fetch source materials')
console.error('Error fetching medicine methods:', error)
throw new Error('Failed to fetch medicine methods')
}
}
@@ -42,8 +42,8 @@ export async function getMedicineMethodDetail(id: number | string) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching source material detail:', error)
throw new Error('Failed to get source material detail')
console.error('Error fetching medicine method detail:', error)
throw new Error('Failed to get medicine method detail')
}
}
@@ -55,8 +55,8 @@ export async function postMedicineMethod(record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting source material:', error)
throw new Error('Failed to post source material')
console.error('Error posting medicine method:', error)
throw new Error('Failed to post medicine method')
}
}
@@ -68,8 +68,8 @@ export async function patchMedicineMethod(id: number | string, record: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting source material:', error)
throw new Error('Failed to put source material')
console.error('Error putting medicine method:', error)
throw new Error('Failed to put medicine method')
}
}
@@ -82,6 +82,6 @@ export async function removeMedicineMethod(id: number | string) {
return result
} catch (error) {
console.error('Error deleting record:', error)
throw new Error('Failed to delete source material')
throw new Error('Failed to delete medicine method')
}
}
+59 -5
View File
@@ -1,8 +1,10 @@
import { xfetch } from '~/composables/useXfetch'
export async function getSourceUoms(params: any = null) {
const mainUrl = '/api/v1/uom'
export async function getUoms(params: any = null) {
try {
let url = '/api/v1/uom'
let url = mainUrl
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
const searchParams = new URLSearchParams()
for (const key in params) {
@@ -13,13 +15,65 @@ export async function getSourceUoms(params: any = null) {
const queryString = searchParams.toString()
if (queryString) url += `?${queryString}`
}
const resp = await xfetch(url, 'GET')
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 source uoms:', error)
throw new Error('Failed to fetch source uoms')
console.error('Error fetching uoms:', error)
throw new Error('Failed to fetch uoms')
}
}
export async function getUomDetail(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 uom detail:', error)
throw new Error('Failed to get uom detail')
}
}
export async function postUom(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 uom:', error)
throw new Error('Failed to post uom')
}
}
export async function patchUom(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 uom:', error)
throw new Error('Failed to put uom')
}
}
export async function removeUom(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 uom')
}
}