fix: update some service and handlers

This commit is contained in:
riefive
2025-10-06 10:09:24 +07:00
parent ecdc5d80d9
commit fe23c75aca
23 changed files with 235 additions and 897 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postDivisionPosition, patchDivisionPosition, removeDivisionPosition } from '~/services/division-position.service'
import { create, update, remove } from '~/services/division-position.service'
export const {
recId,
@@ -15,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postDivisionPosition,
patch: patchDivisionPosition,
remove: removeDivisionPosition,
post: create,
patch: update,
remove: remove,
})
+4 -42
View File
@@ -1,43 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postDivision, patchDivision, removeDivision } from '~/services/division.service'
import {
postDivisionPosition,
patchDivisionPosition,
removeDivisionPosition,
} from '~/services/division-position.service'
function normalizeParentId(payload: any) {
if (payload.parent_id !== undefined && payload.parent_id !== null && payload.parent_id !== '') {
payload.parent_id = Number(payload.parent_id)
if (isNaN(payload.parent_id)) payload.parent_id = null
}
return payload
}
function selectPost(payload: any) {
payload = normalizeParentId(payload)
if (payload.division_id && Number(payload.division_id) > 0) {
return postDivisionPosition
}
delete payload.division_id;
return postDivision
}
function selectPatch(id: number | string, payload: any) {
payload = normalizeParentId(payload)
if (payload.division_id && Number(payload.division_id) > 0) {
return patchDivisionPosition
}
delete payload.division_id;
return patchDivision
}
function selectRemove(payload: any) {
if (payload.division_id && Number(payload.division_id) > 0) {
return removeDivisionPosition
}
return removeDivision
}
import { create, update, remove } from '~/services/division.service'
export const {
recId,
@@ -53,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: (payload: any) => selectPost(payload)(payload),
patch: (id: number | string, payload: any) => selectPatch(id, payload)(id, payload),
remove: (payload: any) => selectRemove(payload)(payload),
post: create,
patch: update,
remove: remove,
})
+4 -4
View File
@@ -1,5 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postInstallation, patchInstallation, removeInstallation } from '~/services/installation.service'
import { create, update, remove } from '~/services/installation.service'
export const {
recId,
@@ -15,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postInstallation,
patch: patchInstallation,
remove: removeInstallation,
post: create,
patch: update,
remove: remove,
})
+4 -4
View File
@@ -1,5 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postMaterial, patchMaterial, removeMaterial } from '~/services/material.service'
import { create, update, remove } from '~/services/material.service'
export const {
recId,
@@ -15,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postMaterial,
patch: patchMaterial,
remove: removeMaterial,
post: create,
patch: update,
remove: remove,
})
+4 -4
View File
@@ -1,5 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postMedicineGroup, patchMedicineGroup, removeMedicineGroup } from '~/services/medicine-group.service'
import { create, update, remove } from '~/services/medicine-group.service'
export const {
recId,
@@ -15,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postMedicineGroup,
patch: patchMedicineGroup,
remove: removeMedicineGroup,
post: create,
patch: update,
remove: remove,
})
+9 -6
View File
@@ -1,5 +1,8 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postMedicineMethod, patchMedicineMethod, removeMedicineMethod } from '~/services/medicine-method.service'
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { create, update, remove } from '~/services/medicine-method.service'
export const {
recId,
@@ -14,8 +17,8 @@ export const {
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postMedicineMethod,
patch: patchMedicineMethod,
remove: removeMedicineMethod,
} = genCrudHandler({
create,
update,
remove,
})
+9 -6
View File
@@ -1,5 +1,8 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postMedicine, patchMedicine, removeMedicine } from '~/services/medicine.service'
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { create, update, remove } from '~/services/medicine.service'
export const {
recId,
@@ -14,8 +17,8 @@ export const {
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postMedicine,
patch: patchMedicine,
remove: removeMedicine,
} = genCrudHandler({
create,
update,
remove,
})
+9 -6
View File
@@ -1,5 +1,8 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postSpecialist, patchSpecialist, removeSpecialist } from '~/services/specialist.service'
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { create, update, remove } from '~/services/specialist.service'
export const {
recId,
@@ -14,8 +17,8 @@ export const {
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postSpecialist,
patch: patchSpecialist,
remove: removeSpecialist,
} = genCrudHandler({
create,
update,
remove,
})
+9 -6
View File
@@ -1,5 +1,8 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postSubspecialist, patchSubspecialist, removeSubspecialist } from '~/services/subspecialist.service'
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { create, update, remove } from '~/services/subspecialist.service'
export const {
recId,
@@ -14,8 +17,8 @@ export const {
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postSubspecialist,
patch: patchSubspecialist,
remove: removeSubspecialist,
} = genCrudHandler({
create,
update,
remove,
})
+26 -6
View File
@@ -1,5 +1,12 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postUnit, patchUnit, removeUnit } from '~/services/unit.service'
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { getList, create, update, remove } from '~/services/unit.service'
// Types
import type { Unit } from "~/models/unit";
export const {
recId,
@@ -14,8 +21,21 @@ export const {
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postUnit,
patch: patchUnit,
remove: removeUnit,
} = genCrudHandler({
create,
update,
remove,
})
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = [];
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Unit) => ({
value: item.id,
label: item.name,
}))
}
return data;
}
+4 -4
View File
@@ -1,5 +1,5 @@
import { createCrudHandler } from '~/handlers/_handler'
import { postUom, patchUom, removeUom } from '~/services/uom.service'
import { create, update, remove } from '~/services/uom.service'
export const {
recId,
@@ -15,7 +15,7 @@ export const {
handleActionRemove,
handleCancelForm,
} = createCrudHandler({
post: postUom,
patch: patchUom,
remove: removeUom,
post: create,
patch: update,
remove: remove,
})
+6 -5
View File
@@ -1,23 +1,24 @@
import * as base from './_crud-base'
const path = '/api/v1/device'
const name = 'device'
export function create(data: any) {
return base.create(path, data, 'device')
return base.create(path, data, name)
}
export function getList(params: any = null) {
return base.getList(path, params, 'device')
return base.getList(path, params, name)
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, 'device')
return base.getDetail(path, id, name)
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, 'device')
return base.update(path, id, data, name)
}
export function remove(id: number | string) {
return base.remove(path, id, 'device')
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/division-position'
const path = '/api/v1/division-position'
const name = '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 function create(data: any) {
return base.create(path, data, name)
}
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 function getList(params: any = null) {
return base.getList(path, params, name)
}
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 function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
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 function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
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')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/division'
const path = '/api/v1/division'
const name = 'division'
export async function getDivisions(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 divisions:', error)
throw new Error('Failed to fetch divisions')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getDivisionDetail(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 detail:', error)
throw new Error('Failed to get division detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postDivision(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:', error)
throw new Error('Failed to post division')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchDivision(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:', error)
throw new Error('Failed to put division')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeDivision(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')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/installation'
const path = '/api/v1/installation'
const name = 'installation'
export async function getInstallations(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 installations:', error)
throw new Error('Failed to fetch installations')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getInstallationDetail(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 installation detail:', error)
throw new Error('Failed to get installation detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postInstallation(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 installation:', error)
throw new Error('Failed to post installation')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchInstallation(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 installation:', error)
throw new Error('Failed to put installation')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeInstallation(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 installation')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/material'
const path = '/api/v1/material'
const name = 'material'
export async function getMaterials(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 materials:', error)
throw new Error('Failed to fetch materials')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMaterialDetail(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 material detail:', error)
throw new Error('Failed to get material detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMaterial(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 material:', error)
throw new Error('Failed to post material')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMaterial(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 material:', error)
throw new Error('Failed to put material')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMaterial(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 material')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine-group'
const path = '/api/v1/medicine-group'
const name = 'medicine-group'
export async function getMedicineGroups(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 medicine groups:', error)
throw new Error('Failed to fetch medicine groups')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMedicineGroupDetail(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 group detail:', error)
throw new Error('Failed to get medicine group detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMedicineGroup(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 group:', error)
throw new Error('Failed to post medicine group')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMedicineGroup(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 group:', error)
throw new Error('Failed to put medicine group')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMedicineGroup(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 group')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -80
View File
@@ -1,87 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine-method'
const path = '/api/v1/medicine-method'
const name = '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 function create(data: any) {
return base.create(path, data, name)
}
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(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 medicine methods:', error)
throw new Error('Failed to fetch medicine methods')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
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 function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
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 function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
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')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine'
const path = '/api/v1/medicine'
const name = 'medicine'
export async function getMedicines(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 medicines:', error)
throw new Error('Failed to fetch medicines')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMedicineDetail(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 detail:', error)
throw new Error('Failed to get medicine detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMedicine(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:', error)
throw new Error('Failed to post medicine')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMedicine(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 patching medicine:', error)
throw new Error('Failed to patch medicine')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMedicine(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 medicine:', error)
throw new Error('Failed to delete medicine')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/specialist'
const path = '/api/v1/specialist'
const name = 'specialist'
export async function getSpecialists(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 specialists:', error)
throw new Error('Failed to fetch specialists')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getSpecialistDetail(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 specialist detail:', error)
throw new Error('Failed to get specialist detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postSpecialist(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 specialist:', error)
throw new Error('Failed to post specialist')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchSpecialist(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 specialist:', error)
throw new Error('Failed to put specialist')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeSpecialist(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 specialist')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/subspecialist'
const path = '/api/v1/subspecialist'
const name = 'subspecialist'
export async function getSubspecialists(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 subspecialists:', error)
throw new Error('Failed to fetch subspecialists')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getSubspecialistDetail(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 subspecialist detail:', error)
throw new Error('Failed to get subspecialist detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postSubspecialist(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 subspecialist:', error)
throw new Error('Failed to post subspecialist')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchSubspecialist(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 subspecialist:', error)
throw new Error('Failed to put subspecialist')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeSubspecialist(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 subspecialist')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/unit'
const path = '/api/v1/unit'
const name = 'unit'
export async function getUnits(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 units:', error)
throw new Error('Failed to fetch units')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getUnitDetail(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 unit detail:', error)
throw new Error('Failed to get unit detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postUnit(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 unit:', error)
throw new Error('Failed to post unit')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchUnit(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 unit:', error)
throw new Error('Failed to put unit')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeUnit(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 unit')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+13 -72
View File
@@ -1,79 +1,20 @@
import { xfetch } from '~/composables/useXfetch'
import * as base from './_crud-base'
const mainUrl = '/api/v1/uom'
const path = '/api/v1/uom'
const name = 'uom'
export async function getUoms(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 uoms:', error)
throw new Error('Failed to fetch uoms')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getUomDetail(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 uom detail:', error)
throw new Error('Failed to get uom detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postUom(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 uom:', error)
throw new Error('Failed to post uom')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchUom(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 uom:', error)
throw new Error('Failed to put uom')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeUom(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 uom')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}