88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { xfetch } from '~/composables/useXfetch'
|
|
|
|
const mainUrl = '/api/v1/medicine-method'
|
|
|
|
export async function getMedicineMethodsPrev() {
|
|
const resp = await xfetch('/api/v1/medicine-method')
|
|
if (resp.success) {
|
|
return (resp.body as Record<string, any>).data
|
|
}
|
|
throw new Error('Failed to fetch medicine methods')
|
|
}
|
|
|
|
export async function getMedicineMethods(params: any = null) {
|
|
try {
|
|
let url = mainUrl
|
|
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
|
|
const searchParams = new URLSearchParams()
|
|
for (const key in params) {
|
|
if (params[key] !== null && params[key] !== undefined && params[key] !== '') {
|
|
searchParams.append(key, params[key])
|
|
}
|
|
}
|
|
const queryString = searchParams.toString()
|
|
if (queryString) url += `?${queryString}`
|
|
}
|
|
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 medicine methods:', error)
|
|
throw new Error('Failed to fetch medicine methods')
|
|
}
|
|
}
|
|
|
|
export async function getMedicineMethodDetail(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 medicine method detail:', error)
|
|
throw new Error('Failed to get medicine method detail')
|
|
}
|
|
}
|
|
|
|
export async function postMedicineMethod(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 medicine method:', error)
|
|
throw new Error('Failed to post medicine method')
|
|
}
|
|
}
|
|
|
|
export async function patchMedicineMethod(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 medicine method:', error)
|
|
throw new Error('Failed to put medicine method')
|
|
}
|
|
}
|
|
|
|
export async function removeMedicineMethod(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 medicine method')
|
|
}
|
|
}
|