Files
gg-backend/frontend/src/api/doctor.ts
T

89 lines
1.9 KiB
TypeScript

import apiClient from "@/api/client";
import toast from "react-hot-toast";
export interface Doctor {
doctorId: string;
name: string;
image?: string;
designation?: string;
workingStatus?: string;
qualification?: string;
isActive: boolean;
globalSortOrder: number;
departments?: {
departmentId: string;
timing?: {
monday?: string;
tuesday?: string;
wednesday?: string;
thursday?: string;
friday?: string;
saturday?: string;
sunday?: string;
additional?: string;
};
}[];
}
export const getDoctorsApi = async () => {
const res = await apiClient.get("/doctors/getAll?admin=true");
return res.data;
};
export const getDoctorByIdApi = async (doctorId: string) => {
const res = await apiClient.get(`/doctors/${doctorId}`);
return res.data;
};
export const createDoctorApi = async (data: Doctor) => {
try {
const res = await apiClient.post("/doctors", data);
toast.success("Doctor created successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to create doctor");
throw error;
}
};
export const updateDoctorApi = async (
doctorId: string,
data: Partial<Doctor>,
action: "toggleStatus" | "updateDetails" = "updateDetails",
) => {
try {
const res = await apiClient.patch(`/doctors/${doctorId}/${action}`, data);
toast.success("Doctor updated successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to update doctor");
throw error;
}
};
export const deleteDoctorApi = async (doctorId: string) => {
try {
const res = await apiClient.delete(`/doctors/${doctorId}`);
toast.success("Doctor deleted successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to delete doctor");
throw error;
}
};
export const getDoctorTimingApi = async (doctorId: string) => {
const res = await apiClient.get(`/doctors/getTimings/${doctorId}`);
return res.data;
};