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
+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')
}
}