2026-05-15 17:58:25 +05:30
|
|
|
import apiClient from "@/api/client";
|
|
|
|
|
import toast from "react-hot-toast";
|
|
|
|
|
|
|
|
|
|
export interface HealthPackage {
|
|
|
|
|
id?: number;
|
|
|
|
|
name: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
price: number;
|
2026-05-18 11:55:55 +05:30
|
|
|
image?: string;
|
2026-05-15 17:58:25 +05:30
|
|
|
discountedPrice?: number;
|
|
|
|
|
inclusions: Record<string, string[]>;
|
|
|
|
|
categoryId: number;
|
|
|
|
|
isActive: boolean;
|
|
|
|
|
isFeatured: boolean;
|
|
|
|
|
sortOrder: number;
|
|
|
|
|
category?: {
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface HealthCategory {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
sortOrder: number;
|
|
|
|
|
isActive: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface HealthInquiry {
|
|
|
|
|
id: number;
|
|
|
|
|
fullName: string;
|
|
|
|
|
mobileNumber: string;
|
|
|
|
|
email?: string;
|
|
|
|
|
age: string;
|
|
|
|
|
gender: string;
|
|
|
|
|
preferredDate: string;
|
|
|
|
|
message?: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
healthPackage?: {
|
|
|
|
|
name: string;
|
|
|
|
|
category?: {
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getHealthCategoriesApi = async () => {
|
|
|
|
|
const res = await apiClient.get("/health-check/categories?admin=true");
|
|
|
|
|
return res.data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getHealthPackagesApi = async () => {
|
|
|
|
|
const res = await apiClient.get("/health-check/packages?admin=true");
|
|
|
|
|
return res.data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const createHealthPackageApi = async (data: Partial<HealthPackage>) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.post("/health-check", data);
|
|
|
|
|
toast.success("Package created successfully");
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to create package");
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const updateHealthPackageApi = async (
|
|
|
|
|
id: number,
|
|
|
|
|
data: Partial<HealthPackage>,
|
|
|
|
|
) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.patch(`/health-check/${id}`, data);
|
|
|
|
|
toast.success("Package updated successfully");
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to update package");
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const deleteHealthPackageApi = async (id: number) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.delete(`/health-check/${id}`);
|
|
|
|
|
toast.success("Package deleted successfully");
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to delete package");
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const createCategoryApi = async (data: {
|
|
|
|
|
name: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
sortOrder: number;
|
|
|
|
|
}) => {
|
2026-05-18 10:58:24 +05:30
|
|
|
try {
|
|
|
|
|
const res = await apiClient.post("/health-check/categories", data);
|
|
|
|
|
|
|
|
|
|
toast.success("Category created successfully");
|
|
|
|
|
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to create category");
|
|
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-05-15 17:58:25 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const updateCategoryApi = async (id: number, data: any) => {
|
2026-05-18 10:58:24 +05:30
|
|
|
try {
|
|
|
|
|
const res = await apiClient.patch(`/health-check/categories/${id}`, data);
|
|
|
|
|
|
|
|
|
|
toast.success("Category updated successfully");
|
|
|
|
|
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to update category");
|
|
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-05-15 17:58:25 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const deleteCategoryApi = async (id: number) => {
|
2026-05-18 10:58:24 +05:30
|
|
|
try {
|
|
|
|
|
const res = await apiClient.delete(`/health-check/categories/${id}`);
|
|
|
|
|
|
|
|
|
|
toast.success("Category deleted successfully");
|
|
|
|
|
|
|
|
|
|
return res.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error(error?.response?.data?.message || "Failed to delete category");
|
|
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-05-15 17:58:25 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getAllInquiriesApi = async (
|
|
|
|
|
page = 1,
|
|
|
|
|
limit = 10,
|
|
|
|
|
filterDate = "",
|
|
|
|
|
startDate = "",
|
|
|
|
|
endDate = "",
|
|
|
|
|
) => {
|
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
|
page: page.toString(),
|
|
|
|
|
limit: limit.toString(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (filterDate) params.append("filterDate", filterDate);
|
|
|
|
|
if (startDate) params.append("startDate", startDate);
|
|
|
|
|
if (endDate) params.append("endDate", endDate);
|
|
|
|
|
|
|
|
|
|
const res = await apiClient.get(
|
|
|
|
|
`/health-check/inquiries?${params.toString()}`,
|
|
|
|
|
);
|
|
|
|
|
return res.data;
|
|
|
|
|
};
|