diff --git a/app/components/content/equipment/list.vue b/app/components/content/equipment/list.vue index 7f7b34a0..00315f43 100644 --- a/app/components/content/equipment/list.vue +++ b/app/components/content/equipment/list.vue @@ -7,6 +7,10 @@ import Header from '~/components/pub/custom-ui/nav-header/prep.vue' import AppEquipmentEntryForm from '~/components/app/equipment/entry-form.vue' import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue' +// Services +import { getSourceMaterials } from "~/services/source-material.service" +import { getSourceUoms } from "~/services/source-uom.service" + const isFormEntryDialogOpen = ref(false) const isRecordConfirmationOpen = ref(false) const recId = ref(0) @@ -24,17 +28,6 @@ const items = [ { value: 'item-3', label: 'Item 3' }, ] -// Fungsi untuk fetch data equipment -async function fetchEquipmentData(params: any) { - // const endpoint = transform('/api/v1/equipment', params) - // return await xfetch(endpoint) - return await xfetch('/api/v1/material') -} - -async function fetchUom() { - return await xfetch('/api/v1/uom') -} - // Menggunakan composable untuk pagination const { data, @@ -45,7 +38,7 @@ const { handleSearch, fetchData: getEquipmentList, } = usePaginatedList({ - fetchFn: fetchEquipmentData, + fetchFn: getSourceMaterials, entityName: 'equipment', }) @@ -176,7 +169,7 @@ const handleCancelConfirmation = () => { } onMounted(async () => { - await fetchUom() + await getSourceUoms() }) diff --git a/app/schemas/material.ts b/app/schemas/material.ts index 7d0a4c7e..27e9c68b 100644 --- a/app/schemas/material.ts +++ b/app/schemas/material.ts @@ -1,14 +1,14 @@ import { z } from 'zod' +import type { EquipmentMaterial } from '~/models/equipment-material' -const schema = z.object({ +const MaterialSchema = z.object({ code: z.string({ required_error: 'Kode harus diisi' }).min(1, 'Kode minimum 1 karakter'), name: z.string({ required_error: 'Nama harus diisi' }).min(1, 'Nama minimum 1 karakter'), uom_code: z.string({ required_error: 'Kode unit harus diisi' }).min(1, 'Kode unit harus diisi'), - item_id: z.string({ required_error: 'Tipe harus diisi' }).min(1, 'Tipe harus diisi'), stock: z.preprocess((val) => Number(val), z.number({ invalid_type_error: 'Stok harus berupa angka' }).min(1, 'Stok harus lebih besar dari 0')), }) -type formData = z.infer +type MaterialFormData = z.infer & EquipmentMaterial -export { schema as MaterialSchema } -export type { formData as MaterialFormData } +export { MaterialSchema } +export type { MaterialFormData } diff --git a/app/services/source-material.service.ts b/app/services/source-material.service.ts new file mode 100644 index 00000000..6de45ff5 --- /dev/null +++ b/app/services/source-material.service.ts @@ -0,0 +1,9 @@ +import { xfetch } from '~/composables/useXfetch' + +export async function getSourceMaterials() { + const resp = await xfetch('/api/v1/material') + if (resp.success) { + return (resp.body as Record).data + } + throw new Error('Failed to fetch source materials') +} diff --git a/app/services/source-uom.service.ts b/app/services/source-uom.service.ts new file mode 100644 index 00000000..2569c05d --- /dev/null +++ b/app/services/source-uom.service.ts @@ -0,0 +1,9 @@ +import { xfetch } from '~/composables/useXfetch' + +export async function getSourceUoms() { + const resp = await xfetch('/api/v1/uom') + if (resp.success) { + return (resp.body as Record).data + } + throw new Error('Failed to fetch source uoms') +}