Files
worldshine-redesign/client/src/services/CustomerService.js
Lixian Zhou a5befe634b
All checks were successful
Build And Deploy Main / build-and-deploy (push) Successful in 44s
fix
2026-03-12 18:50:24 -04:00

125 lines
3.3 KiB
JavaScript

import http from "../http-common";
const getAllActiveCustomers = () => {
return http.get('/customers/active');
};
const getAllCustomers = () => {
return http.get('/customers');
};
const createNewCustomer = (data) => {
data.status = 'active';
return http.post('/customers', data);
};
const createNewClient = (data) => {
data.status = 'active';
return http.post('/clients', data);
}
const updateCustomer = (id, data) => {
return http.put(`/customers/${id}`, data);
}
const updateClient = (id, data) => {
data.status = 'active';
return http.put(`/clients/${id}`, data);
}
const deleteCustomer = (id, data) => {
data.status = 'inactive';
return http.put(`/customers/${id}`, data);
}
const deleteClient = (id, data) => {
data.status = 'inactive';
return http.put(`/clients/${id}`, data);
}
const uploadDriverSignature = (filename, data, options = {}) => {
const safeFilename = `${filename || ''}`.trim();
if (!safeFilename || safeFilename.includes('undefined') || safeFilename.includes('null')) {
throw new Error('Invalid upload filename for avatar/signature.');
}
return http.post(`/files/upload/${encodeURIComponent(safeFilename)}`, data, {
params: options
})
}
const uploadAvatar = (filename, data, requestConfig = {}) => {
const safeFilename = `${filename || ''}`.trim();
if (!safeFilename || safeFilename.includes('undefined') || safeFilename.includes('null')) {
throw new Error('Invalid upload filename for avatar/signature.');
}
return http.post(`/files/upload-general/${encodeURIComponent(safeFilename)}`, data, requestConfig);
}
const getAvatar = (filename) => {
return http.get(`/files/${filename}`);
}
const getAvatarAsBlob = (filename) => {
return http.get(`/files/${filename}`, { responseType: 'blob' });
}
const deleteFile = (data) => {
return http.post(`/files/delete`, data);
}
const getCustomersByNameOrEmail = (nameOrEmail) => {
return http.get(`/customers/search`, {params: {nameOrEmail}});
}
const getClientsByNameOrEmail = (nameOrEmail) => {
return http.get(`/clients/search`, {params: {nameOrEmail}});
}
const getCustomer = (id) => {
return http.get(`customers/${id}`);
}
const getClient = (id) => {
return http.get(`clients/${id}`);
}
const uploadCustomerFile = (data, customerId, name, fileType) => {
return http.post(`/files/upload-physical?objectId=${customerId}&name=${name}&fileType=${fileType}&model=customer`, data);
}
const getAllCustomerFiles = (customerId, name, fileType) => {
return http.get(`/files/list?objectId=${customerId}&name=${name}&fileType=${fileType}&model=customer`);
}
const getCustomerFormFiles = (customerId, customerName, fileType) => {
return http.get(`/files/uploadedDocs/customer/${customerId}/type/${fileType}/name/${encodeURIComponent(customerName)}`);
}
const getFileDownloadUrl = (fileUrl) => {
const baseUrl = http.defaults.baseURL || '';
return baseUrl.replace('/api', '') + fileUrl;
}
export const CustomerService = {
getAllActiveCustomers,
uploadAvatar,
uploadDriverSignature,
getAvatar,
getAvatarAsBlob,
deleteFile,
createNewCustomer,
updateCustomer,
deleteCustomer,
getCustomersByNameOrEmail,
getCustomer,
getAllCustomers,
createNewClient,
updateClient,
deleteClient,
getClientsByNameOrEmail,
getClient,
uploadCustomerFile,
getAllCustomerFiles,
getCustomerFormFiles,
getFileDownloadUrl
};