fix: adjust service base

This commit is contained in:
riefive
2025-11-17 14:44:09 +07:00
parent 9f6f07a987
commit edf21ef5fb
3 changed files with 19 additions and 6 deletions
+17 -4
View File
@@ -74,6 +74,19 @@ export async function update(path: string, id: number | string, data: any, name:
}
}
export async function updateCustom(path: string, data: any, name: string = 'item') {
try {
const resp = await xfetch(`${path}`, 'PATCH', data)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error(`Error putting ${name}:`, error)
throw new Error(`Failed to put ${name}`)
}
}
export async function remove(path: string, id: number | string, name: string = 'item') {
try {
const resp = await xfetch(`${path}/${id}`, 'DELETE')
@@ -87,15 +100,15 @@ export async function remove(path: string, id: number | string, name: string = '
}
}
export async function custom(path: string, data: any, name: string = 'item') {
export async function removeCustom(path: string, data: any, name: string = 'item') {
try {
const resp = await xfetch(`${path}`, 'PATCH', data)
const resp = await xfetch(`${path}`, 'DELETE', data)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error(`Error putting ${name}:`, error)
throw new Error(`Failed to put ${name}`)
console.error(`Error deleting ${name}:`, error)
throw new Error(`Failed to delete ${name}`)
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ export function remove(id: number | string) {
export function cancel(id: number | string) {
let url = `${path}/${id}/cancel`
return base.custom(url, null, name)
return base.updateCustom(url, null, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
+1 -1
View File
@@ -22,7 +22,7 @@ export function getList(params: any = null) {
export function remove(payload: any) {
const url = `${path}`
return base.custom(url, payload, name)
return base.removeCustom(url, payload, name)
}
export function makeSepData(