diff --git a/app/handlers/division.handler.ts b/app/handlers/division.handler.ts new file mode 100644 index 00000000..e830260f --- /dev/null +++ b/app/handlers/division.handler.ts @@ -0,0 +1,21 @@ +import { createCrudHandler } from '~/handlers/_handler' +import { postDivision, patchDivision, removeDivision } from '~/services/division.service' + +export const { + recId, + recAction, + recItem, + isReadonly, + isProcessing, + isFormEntryDialogOpen, + isRecordConfirmationOpen, + onResetState, + handleActionSave, + handleActionEdit, + handleActionRemove, + handleCancelForm, +} = createCrudHandler({ + post: postDivision, + patch: patchDivision, + remove: removeDivision, +}) diff --git a/app/handlers/subspecialist.handler.ts b/app/handlers/subspecialist.handler.ts new file mode 100644 index 00000000..9fc7a67e --- /dev/null +++ b/app/handlers/subspecialist.handler.ts @@ -0,0 +1,21 @@ +import { createCrudHandler } from '~/handlers/_handler' +import { postSubspecialist, patchSubspecialist, removeSubspecialist } from '~/services/subspecialist.service' + +export const { + recId, + recAction, + recItem, + isReadonly, + isProcessing, + isFormEntryDialogOpen, + isRecordConfirmationOpen, + onResetState, + handleActionSave, + handleActionEdit, + handleActionRemove, + handleCancelForm, +} = createCrudHandler({ + post: postSubspecialist, + patch: patchSubspecialist, + remove: removeSubspecialist, +}) diff --git a/app/models/division.ts b/app/models/division.ts new file mode 100644 index 00000000..e9acae24 --- /dev/null +++ b/app/models/division.ts @@ -0,0 +1,4 @@ +export interface Division { + code: string + name: string +} diff --git a/app/models/subspecialist.ts b/app/models/subspecialist.ts new file mode 100644 index 00000000..755508f6 --- /dev/null +++ b/app/models/subspecialist.ts @@ -0,0 +1,5 @@ +export interface Subspecialist { + code: string + name: string + unit_id: number +} diff --git a/app/services/division.service.ts b/app/services/division.service.ts new file mode 100644 index 00000000..38cd6118 --- /dev/null +++ b/app/services/division.service.ts @@ -0,0 +1,79 @@ +import { xfetch } from '~/composables/useXfetch' + +const mainUrl = '/api/v1/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(mainUrl, '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 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 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 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 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') + } +} diff --git a/app/services/subspecialist.service.ts b/app/services/subspecialist.service.ts new file mode 100644 index 00000000..c218b748 --- /dev/null +++ b/app/services/subspecialist.service.ts @@ -0,0 +1,79 @@ +import { xfetch } from '~/composables/useXfetch' + +const mainUrl = '/api/v1/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(mainUrl, '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 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 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 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 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') + } +}