Files
tm_panel/src/lib/api/services/customers-service.ts
T
AmirReza Jamali 83bd4394fc Fixed build issues
2025-09-09 13:32:58 +03:30

79 lines
2.1 KiB
TypeScript

import api from "../axios";
import { API_ENDPOINTS } from "../endpoints";
import {
CreateCustomerCredentials,
CustomerListResponseSchema,
TAssignCustomerToCompanyCredentials,
} from "../types/Customers";
export const customersService = {
getCustomers: async (params?: Record<string, any>) => {
try {
const response = await api.get(API_ENDPOINTS.CUSTOMERS.READ_ALL, {
params,
});
return CustomerListResponseSchema.parse(response.data);
} catch (error) {
console.error("ERROR caught in Customers Services Read all:", error);
throw error;
}
},
deleteCustomer: async (id: string) => {
try {
return (await api.delete(API_ENDPOINTS.CUSTOMERS.DELETE(id))).data;
} catch (error) {
console.error("ERROR caught in Customers Services Delete:", error);
throw error;
}
},
createCustomer: async (credentials: CreateCustomerCredentials) => {
try {
return (await api.post(API_ENDPOINTS.CUSTOMERS.CREATE, credentials)).data;
} catch (error) {
console.error("ERROR caught in Customers Services Create:", error);
throw error;
}
},
updateCustomer: async ({
id,
credentials,
}: {
id: string;
credentials: CreateCustomerCredentials;
}) => {
try {
return (await api.put(API_ENDPOINTS.CUSTOMERS.UPDATE(id), credentials))
.data;
} catch (error) {
console.error("ERROR caught in Customers Services Update:", error);
throw error;
}
},
customerDetails: async (id: string) => {
const response = await api.get(API_ENDPOINTS.CUSTOMERS.DETAILS(id));
return response.data;
},
assignCompanyToCustomer: async ({
credentials,
id,
}: {
id: string;
credentials: TAssignCustomerToCompanyCredentials;
}): Promise<any> => {
try {
return (
await api.post(
API_ENDPOINTS.CUSTOMERS.ASSIGN_COMPANY_TO_CUSTOMER(id),
credentials,
)
).data;
} catch (error) {
console.error(
"ERROR caught in Customers Service => Assign company to customer",
error,
);
throw error;
}
},
};