feat(material): create service get for material and uom

This commit is contained in:
riefive
2025-09-18 13:42:35 +07:00
parent 117e72fdce
commit 29b54b072c
4 changed files with 29 additions and 18 deletions
+6 -13
View File
@@ -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<number>(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()
})
</script>
+5 -5
View File
@@ -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<typeof schema>
type MaterialFormData = z.infer<typeof MaterialSchema> & EquipmentMaterial
export { schema as MaterialSchema }
export type { formData as MaterialFormData }
export { MaterialSchema }
export type { MaterialFormData }
+9
View File
@@ -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<string, any>).data
}
throw new Error('Failed to fetch source materials')
}
+9
View File
@@ -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<string, any>).data
}
throw new Error('Failed to fetch source uoms')
}