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;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
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;
|
||||
}
|
||||
},
|
||||
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;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./user-services";
|
||||
export * from "./companies-service";
|
||||
export * from "./tenders-service";
|
||||
export * from "./profile-service";
|
||||
@@ -0,0 +1,15 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import { CurrentUserProfileSchema } from "../types";
|
||||
export const profileService = {
|
||||
getProfile: async () => {
|
||||
try {
|
||||
const response = (await api.get(API_ENDPOINTS.PROFILE.READ)).data;
|
||||
|
||||
return CurrentUserProfileSchema.parse(response.data);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Profile Service: Get Profile", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import { ApiResponse } from "../types";
|
||||
import { TTenderResponse } from "../types/Tenders";
|
||||
|
||||
export const tendersService = {
|
||||
tendersList: async (
|
||||
params?: Record<string, any>,
|
||||
): Promise<ApiResponse<TTenderResponse>> => {
|
||||
try {
|
||||
return (await api.get(API_ENDPOINTS.TENDERS.READ_ALL, { params })).data;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Tenders Services Read all:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import {
|
||||
AdminListResponseSchema,
|
||||
ApiResponse,
|
||||
IAdminListResponse,
|
||||
ICreateAdminCredentials,
|
||||
ILoginCredentials,
|
||||
ILoginResponse,
|
||||
ILogoutResponse,
|
||||
LoginResponseSchema,
|
||||
LogoutResponseSchema,
|
||||
} from "../types";
|
||||
|
||||
export const userService = {
|
||||
login: async (
|
||||
credentials: ILoginCredentials
|
||||
): Promise<ApiResponse<ILoginResponse>> => {
|
||||
try {
|
||||
const response = await api.post(API_ENDPOINTS.USER.LOGIN, credentials);
|
||||
|
||||
return LoginResponseSchema.parse(response.data);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Login:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
logout: async (): Promise<ApiResponse<ILogoutResponse>> => {
|
||||
try {
|
||||
const response = await api.delete(API_ENDPOINTS.USER.LOGOUT);
|
||||
return LogoutResponseSchema.parse(response.data);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Logout", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
adminsList: async (
|
||||
params?: Record<string, any>
|
||||
): Promise<ApiResponse<IAdminListResponse>> => {
|
||||
try {
|
||||
const response = await api.get(API_ENDPOINTS.USER.ADMINS, { params });
|
||||
return AdminListResponseSchema.parse(response.data);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service User List", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
createAdmin: async (credentials: ICreateAdminCredentials) => {
|
||||
try {
|
||||
return (await api.post(API_ENDPOINTS.USER.ADMINS, credentials)).data
|
||||
.message;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Create Admin", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
updateAdmin: async ({
|
||||
id,
|
||||
credentials,
|
||||
}: {
|
||||
id: string;
|
||||
credentials: ICreateAdminCredentials;
|
||||
}) => {
|
||||
try {
|
||||
return (await api.put(API_ENDPOINTS.USER.ADMIN_DETAILS(id), credentials))
|
||||
.data.message;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Update Admin", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
adminDetails: async (id: string) => {
|
||||
try {
|
||||
return (await api.get(API_ENDPOINTS.USER.ADMIN_DETAILS(id))).data;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Admin Details", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
deleteAdmin: async (
|
||||
id: string
|
||||
): Promise<ApiResponse<{ message: string }>> => {
|
||||
try {
|
||||
return await api.delete(`${API_ENDPOINTS.USER.ADMINS}/${id}`);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in User Service Delete Admin", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user