feat(medicine): add models + service
This commit is contained in:
@@ -9,6 +9,6 @@ const props = defineProps({
|
||||
<template>
|
||||
<div :class="`${props.defaultClass} ${props.class}`">
|
||||
<slot />
|
||||
<div v-if="props.errMessage" class="text-red-500">{{ props.errMessage }}</div>
|
||||
<div v-if="props.errMessage" class="mt-1 text-xs font-medium text-red-500">{{ props.errMessage }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Default item meta model for entities
|
||||
export interface ItemMeta {
|
||||
id: number;
|
||||
createdAt: string | null;
|
||||
deletedAt: string | null;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
// Pagination meta model for API responses
|
||||
export interface PaginationMeta {
|
||||
page_number: string;
|
||||
page_size: string;
|
||||
record_totalCount: string;
|
||||
source: string;
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
const mainUrl = '/api/v1/device'
|
||||
|
||||
export async function getSourceDevices(params: any = null) {
|
||||
try {
|
||||
let url = '/api/v1/device'
|
||||
let url = mainUrl
|
||||
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
|
||||
const searchParams = new URLSearchParams()
|
||||
for (const key in params) {
|
||||
@@ -26,7 +28,7 @@ export async function getSourceDevices(params: any = null) {
|
||||
|
||||
export async function getSourceDeviceDetail(id: string | number) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/device/${id}`, 'GET')
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'GET')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -39,7 +41,7 @@ export async function getSourceDeviceDetail(id: string | number) {
|
||||
|
||||
export async function postSourceDevice(data: any) {
|
||||
try {
|
||||
const resp = await xfetch('/api/v1/device', 'POST', data)
|
||||
const resp = await xfetch(mainUrl, 'POST', data)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -52,7 +54,7 @@ export async function postSourceDevice(data: any) {
|
||||
|
||||
export async function patchSourceDevice(id: string | number, data: any) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/device/${id}`, 'PATCH', data)
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', data)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -65,7 +67,7 @@ export async function patchSourceDevice(id: string | number, data: any) {
|
||||
|
||||
export async function removeSourceDevice(id: string | number) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/device/${id}`, 'DELETE')
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
const mainUrl = '/api/v1/material'
|
||||
|
||||
export async function getSourceMaterials(params: any = null) {
|
||||
try {
|
||||
let url = '/api/v1/material'
|
||||
let url = mainUrl
|
||||
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
|
||||
const searchParams = new URLSearchParams()
|
||||
for (const key in params) {
|
||||
@@ -26,7 +28,7 @@ export async function getSourceMaterials(params: any = null) {
|
||||
|
||||
export async function getSourceMaterialDetail(id: number | string) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/material/${id}`, 'GET')
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'GET')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -39,7 +41,7 @@ export async function getSourceMaterialDetail(id: number | string) {
|
||||
|
||||
export async function postSourceMaterial(record: any) {
|
||||
try {
|
||||
const resp = await xfetch('/api/v1/material', 'POST', record)
|
||||
const resp = await xfetch(mainUrl, 'POST', record)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -52,7 +54,7 @@ export async function postSourceMaterial(record: any) {
|
||||
|
||||
export async function patchSourceMaterial(id: number | string, record: any) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/material/${id}`, 'PATCH', record)
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
@@ -65,7 +67,7 @@ export async function patchSourceMaterial(id: number | string, record: any) {
|
||||
|
||||
export async function removeSourceMaterial(id: number | string) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/material/${id}`, 'DELETE')
|
||||
const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
const mainUrl = '/api/v1/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(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 source materials:', error)
|
||||
throw new Error('Failed to fetch source materials')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material detail:', error)
|
||||
throw new Error('Failed to get source material detail')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material:', error)
|
||||
throw new Error('Failed to post source material')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material:', error)
|
||||
throw new Error('Failed to put source material')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material')
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,87 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
export async function getMedicineMethods() {
|
||||
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 source materials:', error)
|
||||
throw new Error('Failed to fetch source materials')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material detail:', error)
|
||||
throw new Error('Failed to get source material 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 source material:', error)
|
||||
throw new Error('Failed to post source material')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material:', error)
|
||||
throw new Error('Failed to put source material')
|
||||
}
|
||||
}
|
||||
|
||||
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 source material')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user