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