From fe23c75aca2905c9de2707690eef9a0487b4bb98 Mon Sep 17 00:00:00 2001 From: riefive Date: Mon, 6 Oct 2025 10:09:24 +0700 Subject: [PATCH] fix: update some service and handlers --- app/handlers/division-position.handler.ts | 8 +- app/handlers/division.handler.ts | 46 +---------- app/handlers/installation.handler.ts | 8 +- app/handlers/material.handler.ts | 8 +- app/handlers/medicine-group.handler.ts | 8 +- app/handlers/medicine-method.handler.ts | 15 ++-- app/handlers/medicine.handler.ts | 15 ++-- app/handlers/specialist.handler.ts | 15 ++-- app/handlers/subspecialist.handler.ts | 15 ++-- app/handlers/unit.handler.ts | 32 ++++++-- app/handlers/uom.handler.ts | 8 +- app/services/device.service.ts | 11 +-- app/services/division-position.service.ts | 85 ++++----------------- app/services/division.service.ts | 85 ++++----------------- app/services/installation.service.ts | 85 ++++----------------- app/services/material.service.ts | 85 ++++----------------- app/services/medicine-group.service.ts | 85 ++++----------------- app/services/medicine-method.service.ts | 93 ++++------------------- app/services/medicine.service.ts | 85 ++++----------------- app/services/specialist.service.ts | 85 ++++----------------- app/services/subspecialist.service.ts | 85 ++++----------------- app/services/unit.service.ts | 85 ++++----------------- app/services/uom.service.ts | 85 ++++----------------- 23 files changed, 235 insertions(+), 897 deletions(-) diff --git a/app/handlers/division-position.handler.ts b/app/handlers/division-position.handler.ts index dcbfc7fd..04e016c6 100644 --- a/app/handlers/division-position.handler.ts +++ b/app/handlers/division-position.handler.ts @@ -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, }) diff --git a/app/handlers/division.handler.ts b/app/handlers/division.handler.ts index 31e24411..803ccbee 100644 --- a/app/handlers/division.handler.ts +++ b/app/handlers/division.handler.ts @@ -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, }) diff --git a/app/handlers/installation.handler.ts b/app/handlers/installation.handler.ts index d3a1d06e..864738be 100644 --- a/app/handlers/installation.handler.ts +++ b/app/handlers/installation.handler.ts @@ -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, }) diff --git a/app/handlers/material.handler.ts b/app/handlers/material.handler.ts index 750f7967..dd7dd4ff 100644 --- a/app/handlers/material.handler.ts +++ b/app/handlers/material.handler.ts @@ -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, }) diff --git a/app/handlers/medicine-group.handler.ts b/app/handlers/medicine-group.handler.ts index 998ab285..6e61fff2 100644 --- a/app/handlers/medicine-group.handler.ts +++ b/app/handlers/medicine-group.handler.ts @@ -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, }) diff --git a/app/handlers/medicine-method.handler.ts b/app/handlers/medicine-method.handler.ts index df4e0ff9..9ba6288b 100644 --- a/app/handlers/medicine-method.handler.ts +++ b/app/handlers/medicine-method.handler.ts @@ -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, }) diff --git a/app/handlers/medicine.handler.ts b/app/handlers/medicine.handler.ts index d550f11b..8def5dc3 100644 --- a/app/handlers/medicine.handler.ts +++ b/app/handlers/medicine.handler.ts @@ -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, }) diff --git a/app/handlers/specialist.handler.ts b/app/handlers/specialist.handler.ts index 445f8c15..476c7ec8 100644 --- a/app/handlers/specialist.handler.ts +++ b/app/handlers/specialist.handler.ts @@ -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, }) diff --git a/app/handlers/subspecialist.handler.ts b/app/handlers/subspecialist.handler.ts index 9fc7a67e..bd12b146 100644 --- a/app/handlers/subspecialist.handler.ts +++ b/app/handlers/subspecialist.handler.ts @@ -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, }) diff --git a/app/handlers/unit.handler.ts b/app/handlers/unit.handler.ts index ff235bb4..49d1b175 100644 --- a/app/handlers/unit.handler.ts +++ b/app/handlers/unit.handler.ts @@ -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; +} \ No newline at end of file diff --git a/app/handlers/uom.handler.ts b/app/handlers/uom.handler.ts index dd018400..e4062fe1 100644 --- a/app/handlers/uom.handler.ts +++ b/app/handlers/uom.handler.ts @@ -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, }) diff --git a/app/services/device.service.ts b/app/services/device.service.ts index 003d7371..5e6a7b1f 100644 --- a/app/services/device.service.ts +++ b/app/services/device.service.ts @@ -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) } diff --git a/app/services/division-position.service.ts b/app/services/division-position.service.ts index 1c1855af..f2cc854d 100644 --- a/app/services/division-position.service.ts +++ b/app/services/division-position.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/division.service.ts b/app/services/division.service.ts index e58af288..3801b399 100644 --- a/app/services/division.service.ts +++ b/app/services/division.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/installation.service.ts b/app/services/installation.service.ts index aaa38c03..48e633a3 100644 --- a/app/services/installation.service.ts +++ b/app/services/installation.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/material.service.ts b/app/services/material.service.ts index 098612e0..05006f3f 100644 --- a/app/services/material.service.ts +++ b/app/services/material.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/medicine-group.service.ts b/app/services/medicine-group.service.ts index cd2be9f0..6eb993e1 100644 --- a/app/services/medicine-group.service.ts +++ b/app/services/medicine-group.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } \ No newline at end of file diff --git a/app/services/medicine-method.service.ts b/app/services/medicine-method.service.ts index 44f17f34..3c41e496 100644 --- a/app/services/medicine-method.service.ts +++ b/app/services/medicine-method.service.ts @@ -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).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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/medicine.service.ts b/app/services/medicine.service.ts index 04860455..1c7fc7dc 100644 --- a/app/services/medicine.service.ts +++ b/app/services/medicine.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/specialist.service.ts b/app/services/specialist.service.ts index 4e1c2634..e2531bb2 100644 --- a/app/services/specialist.service.ts +++ b/app/services/specialist.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/subspecialist.service.ts b/app/services/subspecialist.service.ts index a5356353..6b427d43 100644 --- a/app/services/subspecialist.service.ts +++ b/app/services/subspecialist.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/unit.service.ts b/app/services/unit.service.ts index 052fb707..bdee834a 100644 --- a/app/services/unit.service.ts +++ b/app/services/unit.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } diff --git a/app/services/uom.service.ts b/app/services/uom.service.ts index e01b59b3..13b3647e 100644 --- a/app/services/uom.service.ts +++ b/app/services/uom.service.ts @@ -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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) || {} - 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) } \ No newline at end of file