fix: change integrate material
This commit is contained in:
@@ -2,38 +2,34 @@ import { xfetch } from '~/composables/useXfetch'
|
||||
|
||||
export async function getSourceMaterials(params: any = null) {
|
||||
try {
|
||||
let url = '/api/v1/material';
|
||||
let url = '/api/v1/material'
|
||||
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
|
||||
const searchParams = new URLSearchParams();
|
||||
const searchParams = new URLSearchParams()
|
||||
for (const key in params) {
|
||||
if (params[key] !== null && params[key] !== undefined && params[key] !== '') {
|
||||
searchParams.append(key, params[key]);
|
||||
searchParams.append(key, params[key])
|
||||
}
|
||||
}
|
||||
const queryString = searchParams.toString();
|
||||
if (queryString) url += `?${queryString}`;
|
||||
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;
|
||||
const resp = await xfetch(url, 'GET')
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error fetching source materials:', error);
|
||||
throw new Error('Failed to fetch source materials');
|
||||
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 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
|
||||
}
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error fetching source material detail:', error)
|
||||
@@ -43,12 +39,10 @@ export async function getSourceMaterialDetail(id: number | string) {
|
||||
|
||||
export async function postSourceMaterial(record: any) {
|
||||
try {
|
||||
const resp = await xfetch('/api/v1/material', 'POST', record);
|
||||
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
|
||||
}
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error posting source material:', error)
|
||||
@@ -58,12 +52,10 @@ export async function postSourceMaterial(record: any) {
|
||||
|
||||
export async function putSourceMaterial(id: number | string, record: any) {
|
||||
try {
|
||||
const resp = await xfetch(`/api/v1/material/${id}`, 'PUT', record);
|
||||
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
|
||||
}
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error putting source material:', error)
|
||||
@@ -76,9 +68,7 @@ export async function removeSourceMaterial(id: number | string) {
|
||||
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
|
||||
}
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error deleting record:', error)
|
||||
|
||||
@@ -16,9 +16,7 @@ export async function getSourceUoms(params: any = null) {
|
||||
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
|
||||
}
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error fetching source uoms:', error)
|
||||
|
||||
Reference in New Issue
Block a user