feat(unit): add unit and installation service models
This commit is contained in:
@@ -1,19 +1,35 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { PaginationMeta } from '~/components/pub/custom-ui/pagination/pagination.type'
|
||||||
|
import PaginationView from '~/components/pub/custom-ui/pagination/pagination-view.vue'
|
||||||
import { cols, funcComponent, funcHtml, funcParsed, header, keys } from './list-cfg'
|
import { cols, funcComponent, funcHtml, funcParsed, header, keys } from './list-cfg'
|
||||||
|
|
||||||
defineProps<{
|
interface Props {
|
||||||
data: any[]
|
data: any[]
|
||||||
|
paginationMeta: PaginationMeta
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
pageChange: [page: number]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
function handlePageChange(page: number) {
|
||||||
|
emit('pageChange', page)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<PubBaseDataTable
|
<div class="space-y-4">
|
||||||
:rows="data"
|
<PubBaseDataTable
|
||||||
:cols="cols"
|
:rows="data"
|
||||||
:header="header"
|
:cols="cols"
|
||||||
:keys="keys"
|
:header="header"
|
||||||
:func-parsed="funcParsed"
|
:keys="keys"
|
||||||
:func-html="funcHtml"
|
:func-parsed="funcParsed"
|
||||||
:func-component="funcComponent"
|
:func-html="funcHtml"
|
||||||
/>
|
:func-component="funcComponent"
|
||||||
|
/>
|
||||||
|
<PaginationView :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { createCrudHandler } from '~/handlers/_handler'
|
||||||
|
import { postInstallation, patchInstallation, removeInstallation } from '~/services/installation.service'
|
||||||
|
|
||||||
|
export const {
|
||||||
|
recId,
|
||||||
|
recAction,
|
||||||
|
recItem,
|
||||||
|
isReadonly,
|
||||||
|
isProcessing,
|
||||||
|
isFormEntryDialogOpen,
|
||||||
|
isRecordConfirmationOpen,
|
||||||
|
onResetState,
|
||||||
|
handleActionSave,
|
||||||
|
handleActionEdit,
|
||||||
|
handleActionRemove,
|
||||||
|
handleCancelForm,
|
||||||
|
} = createCrudHandler({
|
||||||
|
post: postInstallation,
|
||||||
|
patch: patchInstallation,
|
||||||
|
remove: removeInstallation,
|
||||||
|
})
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { createCrudHandler } from '~/handlers/_handler'
|
||||||
|
import { postUnit, patchUnit, removeUnit } from '~/services/unit.service'
|
||||||
|
|
||||||
|
export const {
|
||||||
|
recId,
|
||||||
|
recAction,
|
||||||
|
recItem,
|
||||||
|
isReadonly,
|
||||||
|
isProcessing,
|
||||||
|
isFormEntryDialogOpen,
|
||||||
|
isRecordConfirmationOpen,
|
||||||
|
onResetState,
|
||||||
|
handleActionSave,
|
||||||
|
handleActionEdit,
|
||||||
|
handleActionRemove,
|
||||||
|
handleCancelForm,
|
||||||
|
} = createCrudHandler({
|
||||||
|
post: postUnit,
|
||||||
|
patch: patchUnit,
|
||||||
|
remove: removeUnit,
|
||||||
|
})
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export interface Installation {
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
encounterClass_code: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export interface Unit {
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
installation: string | number
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { xfetch } from '~/composables/useXfetch'
|
||||||
|
|
||||||
|
const mainUrl = '/api/v1/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(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 installations:', error)
|
||||||
|
throw new Error('Failed to fetch installations')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 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 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')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { xfetch } from '~/composables/useXfetch'
|
||||||
|
|
||||||
|
const mainUrl = '/api/v1/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(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 units:', error)
|
||||||
|
throw new Error('Failed to fetch units')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 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 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')
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user