feat(material): modify handlers and service of material

This commit is contained in:
riefive
2025-09-19 15:23:09 +07:00
parent 29b54b072c
commit 70378a69e9
11 changed files with 244 additions and 142 deletions
+87
View File
@@ -0,0 +1,87 @@
import { xfetch } from '~/composables/useXfetch'
export async function getSourceMaterials(params: any = null) {
try {
let url = '/api/v1/material';
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;
if (resp.success) {
result.data = (resp.body as Record<string, any>).data;
}
return result;
} catch (error) {
console.error('Error fetching source materials:', error);
throw new Error('Failed to fetch source materials');
}
}
export async function getSourceMaterialDetail(id: number | string) {
try {
const resp = await xfetch(`/api/v1/material/${id}`, 'GET');
const result: any = {}
result.success = resp.success
if (resp.success) {
result.data = (resp.body as Record<string, any>).data
}
return result
} catch (error) {
console.error('Error fetching source material detail:', error)
throw new Error('Failed to get source material detail')
}
}
export async function postSourceMaterial(record: any) {
try {
const resp = await xfetch('/api/v1/material', 'POST', record);
const result: any = {}
result.success = resp.success
if (resp.success) {
result.data = (resp.body as Record<string, any>).data
}
return result
} catch (error) {
console.error('Error posting source material:', error)
throw new Error('Failed to post source material')
}
}
export async function putSourceMaterial(id: number | string, record: any) {
try {
const resp = await xfetch(`/api/v1/material/${id}`, 'PUT', record);
const result: any = {}
result.success = resp.success
if (resp.success) {
result.data = (resp.body as Record<string, any>).data
}
return result
} catch (error) {
console.error('Error putting source material:', error)
throw new Error('Failed to put source material')
}
}
export async function removeSourceMaterial(id: number | string) {
try {
const resp = await xfetch(`/api/v1/material/${id}`, 'DELETE')
const result: any = {}
result.success = resp.success
if (resp.success) {
result.data = (resp.body as Record<string, any>).data
}
return result
} catch (error) {
console.error('Error deleting record:', error)
throw new Error('Failed to delete source material')
}
}
-9
View File
@@ -1,9 +0,0 @@
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
@@ -1,9 +0,0 @@
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')
}
+27
View File
@@ -0,0 +1,27 @@
import { xfetch } from '~/composables/useXfetch'
export async function getSourceUoms(params: any = null) {
try {
let url = '/api/v1/uom'
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
if (resp.success) {
result.data = (resp.body as Record<string, any>).data
}
return result
} catch (error) {
console.error('Error fetching source uoms:', error)
throw new Error('Failed to fetch source uoms')
}
}