Initial commit for new panel
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import {
|
||||
ApiResponse,
|
||||
CompaniesListResponseSchema,
|
||||
TCompaniesResponse,
|
||||
} from "../types";
|
||||
|
||||
import { ICreateCompanyCredentials } from "../types";
|
||||
|
||||
export const companiesService = {
|
||||
getCompanies: async (
|
||||
params?: Record<string, any>,
|
||||
): Promise<ApiResponse<TCompaniesResponse>> => {
|
||||
try {
|
||||
const response = await api.get(API_ENDPOINTS.COMPANIES.READ_ALL, {
|
||||
params,
|
||||
});
|
||||
|
||||
return CompaniesListResponseSchema.parse(response.data);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Companies Services Read all:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
createCompany: async (credentials: ICreateCompanyCredentials) => {
|
||||
const response = await api.post(
|
||||
API_ENDPOINTS.COMPANIES.CREATE,
|
||||
credentials,
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
updateCompany: async ({
|
||||
id,
|
||||
credentials,
|
||||
}: {
|
||||
id: string;
|
||||
credentials: ICreateCompanyCredentials;
|
||||
}) => {
|
||||
const response = await api.put(
|
||||
API_ENDPOINTS.COMPANIES.UPDATE(id),
|
||||
credentials,
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
companyDetails: async (id: string) => {
|
||||
const response = await api.get(API_ENDPOINTS.COMPANIES.DETAILS(id));
|
||||
return response.data;
|
||||
},
|
||||
deleteCompany: async (id: string) => {
|
||||
try {
|
||||
return (await api.delete(API_ENDPOINTS.COMPANIES.DELETE(id))).data;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Companies Services Delete:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user