fix: adjust service base
This commit is contained in:
No files matched your search
@@ -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') {
|
export async function remove(path: string, id: number | string, name: string = 'item') {
|
||||||
try {
|
try {
|
||||||
const resp = await xfetch(`${path}/${id}`, 'DELETE')
|
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 {
|
try {
|
||||||
const resp = await xfetch(`${path}`, 'PATCH', data)
|
const resp = await xfetch(`${path}`, 'DELETE', data)
|
||||||
const result: any = {}
|
const result: any = {}
|
||||||
result.success = resp.success
|
result.success = resp.success
|
||||||
result.body = (resp.body as Record<string, any>) || {}
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error putting ${name}:`, error)
|
console.error(`Error deleting ${name}:`, error)
|
||||||
throw new Error(`Failed to put ${name}`)
|
throw new Error(`Failed to delete ${name}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ export function remove(id: number | string) {
|
|||||||
|
|
||||||
export function cancel(id: number | string) {
|
export function cancel(id: number | string) {
|
||||||
let url = `${path}/${id}/cancel`
|
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 }[]> {
|
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) {
|
export function remove(payload: any) {
|
||||||
const url = `${path}`
|
const url = `${path}`
|
||||||
return base.custom(url, payload, name)
|
return base.removeCustom(url, payload, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeSepData(
|
export function makeSepData(
|
||||||
|
|||||||
Reference in New Issue
Block a user