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

88 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-03-17 13:11:00 +05:30
import apiClient from "@/api/client";
2026-05-11 10:51:34 +05:30
import toast from "react-hot-toast";
2026-03-17 13:11:00 +05:30
export interface Doctor {
doctorId: string;
name: string;
2026-04-14 17:33:21 +05:30
image?: string;
2026-03-17 13:11:00 +05:30
designation?: string;
workingStatus?: string;
qualification?: string;
2026-05-13 14:19:42 +05:30
isActive: boolean;
globalSortOrder: number;
2026-03-17 16:22:37 +05:30
2026-05-13 14:19:42 +05:30
departments?: {
2026-03-17 16:22:37 +05:30
departmentId: string;
timing?: {
monday?: string;
tuesday?: string;
wednesday?: string;
thursday?: string;
friday?: string;
saturday?: string;
sunday?: string;
additional?: string;
};
}[];
2026-03-17 13:11:00 +05:30
}
export const getDoctorsApi = async () => {
const res = await apiClient.get("/doctors/getAll?admin=true");
2026-03-17 13:11:00 +05:30
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) => {
2026-05-11 10:51:34 +05:30
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;
}
2026-03-17 13:11:00 +05:30
};
export const updateDoctorApi = async (
doctorId: string,
data: Partial<Doctor>,
) => {
2026-05-11 10:51:34 +05:30
try {
const res = await apiClient.patch(`/doctors/${doctorId}`, data);
toast.success("Doctor updated successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to update doctor");
throw error;
}
2026-03-17 13:11:00 +05:30
};
export const deleteDoctorApi = async (doctorId: string) => {
2026-05-11 10:51:34 +05:30
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;
}
2026-03-17 13:11:00 +05:30
};
export const getDoctorTimingApi = async (doctorId: string) => {
const res = await apiClient.get(`/doctors/getTimings/${doctorId}`);
return res.data;
};