fix: adjust service base
This commit is contained in:
@@ -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}`)
|
||||
}
|
||||
}
|
||||
@@ -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 }[]> {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user