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

89 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-05-26 15:48:01 +05:30
import apiClient from '@/api/client';
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 () => {
2026-05-26 15:48:01 +05:30
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 {
2026-05-26 15:48:01 +05:30
const res = await apiClient.post('/doctors', data);
2026-05-11 10:51:34 +05:30
2026-05-26 15:48:01 +05:30
toast.success('Doctor created successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to create doctor');
2026-05-11 10:51:34 +05:30
throw error;
}
2026-03-17 13:11:00 +05:30
};
export const updateDoctorApi = async (
doctorId: string,
data: Partial<Doctor>,
2026-05-26 15:48:01 +05:30
action: 'toggleStatus' | 'updateDetails' = 'updateDetails'
2026-03-17 13:11:00 +05:30
) => {
2026-05-11 10:51:34 +05:30
try {
2026-05-22 16:34:37 +05:30
const res = await apiClient.patch(`/doctors/${doctorId}/${action}`, data);
2026-05-11 10:51:34 +05:30
2026-05-26 15:48:01 +05:30
toast.success('Doctor updated successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to update doctor');
2026-05-11 10:51:34 +05:30
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}`);
2026-05-26 15:48:01 +05:30
toast.success('Doctor deleted successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to delete doctor');
2026-05-11 10:51:34 +05:30
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;
};