80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import { xfetch } from '~/composables/useXfetch'
|
|
|
|
const mainUrl = '/api/v1/division-position'
|
|
|
|
export async function getDivisionPositions(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(url, 'GET')
|
|
const result: any = {}
|
|
result.success = resp.success
|
|
result.body = (resp.body as Record<string, any>) || {}
|
|
return result
|
|
} catch (error) {
|
|
console.error('Error fetching division-positions:', error)
|
|
throw new Error('Failed to fetch division-positions')
|
|
}
|
|
}
|
|
|
|
export async function getDivisionPositionDetail(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 division-position detail:', error)
|
|
throw new Error('Failed to get division-position detail')
|
|
}
|
|
}
|
|
|
|
export async function postDivisionPosition(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 division-position:', error)
|
|
throw new Error('Failed to post division-position')
|
|
}
|
|
}
|
|
|
|
export async function patchDivisionPosition(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 division-position:', error)
|
|
throw new Error('Failed to put division-position')
|
|
}
|
|
}
|
|
|
|
export async function removeDivisionPosition(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 division-position')
|
|
}
|
|
}
|