11import { createApi } from "@reduxjs/toolkit/query/react" ;
22import { baseQueryWithReauth , CACHE_TIMES } from "../core/baseApi" ;
3- import { cacheUtils } from "../../utils/cache" ;
43
54export const appointmentApi = createApi ( {
65 reducerPath : "appointmentApi" ,
@@ -29,12 +28,12 @@ export const appointmentApi = createApi({
2928 } ) ,
3029
3130 getDoctorAvailability : builder . query ( {
32- query : ( { doctorId , date } ) => {
31+ query : ( { doctor_id , date } ) => {
3332 const queryParams = new URLSearchParams ( ) ;
3433 if ( date ) queryParams . append ( "date" , date ) ;
3534
3635 return {
37- url : `appointments/doctors/${ doctorId } /availability?${ queryParams } ` ,
36+ url : `appointments/doctors/${ doctor_id } /availability?${ queryParams } ` ,
3837 method : "GET" ,
3938 } ;
4039 } ,
@@ -53,7 +52,6 @@ export const appointmentApi = createApi({
5352 async onQueryStarted ( arg , { dispatch, queryFulfilled } ) {
5453 try {
5554 await queryFulfilled ;
56- cacheUtils . appointments . clearAll ( ) ;
5755 } catch ( error ) {
5856 console . error ( "Failed to create appointment:" , error ) ;
5957 }
@@ -66,11 +64,14 @@ export const appointmentApi = createApi({
6664 const queryParams = new URLSearchParams ( ) ;
6765
6866 if ( params . status ) queryParams . append ( "status" , params . status ) ;
67+ if ( params . status_not ) queryParams . append ( "status_not" , params . status_not ) ;
68+ if ( params . date_from ) queryParams . append ( "date_from" , params . date_from ) ;
69+ if ( params . date_to ) queryParams . append ( "date_to" , params . date_to ) ;
6970 if ( params . page ) queryParams . append ( "page" , params . page . toString ( ) ) ;
7071 if ( params . limit ) queryParams . append ( "limit" , params . limit . toString ( ) ) ;
7172
7273 return {
73- url : `appointments/` ,
74+ url : `appointments/? ${ queryParams } ` ,
7475 method : "GET" ,
7576 } ;
7677 } ,
@@ -80,16 +81,17 @@ export const appointmentApi = createApi({
8081
8182 // Get patient's appointments by patient ID
8283 getPatientAppointments : builder . query ( {
83- query : ( { patientId , ...params } ) => {
84+ query : ( { patient_id , ...params } ) => {
8485 const queryParams = new URLSearchParams ( ) ;
8586
8687 if ( params . status ) queryParams . append ( "status" , params . status ) ;
8788 if ( params . date_from ) queryParams . append ( "date_from" , params . date_from ) ;
89+ if ( params . date_to ) queryParams . append ( "date_to" , params . date_to ) ;
8890 if ( params . page ) queryParams . append ( "page" , params . page . toString ( ) ) ;
8991 if ( params . limit ) queryParams . append ( "limit" , params . limit . toString ( ) ) ;
9092
9193 return {
92- url : `appointments/patient/${ patientId } ?${ queryParams } ` ,
94+ url : `appointments/patient/${ patient_id } ?${ queryParams } ` ,
9395 method : "GET" ,
9496 } ;
9597 } ,
@@ -103,7 +105,10 @@ export const appointmentApi = createApi({
103105 const queryParams = new URLSearchParams ( ) ;
104106
105107 if ( params . status ) queryParams . append ( "status" , params . status ) ;
108+ if ( params . status_not ) queryParams . append ( "status_not" , params . status_not ) ;
106109 if ( params . doctor_id ) queryParams . append ( "doctor_id" , params . doctor_id ) ;
110+ if ( params . date_from ) queryParams . append ( "date_from" , params . date_from ) ;
111+ if ( params . date_to ) queryParams . append ( "date_to" , params . date_to ) ;
107112 if ( params . page ) queryParams . append ( "page" , params . page . toString ( ) ) ;
108113 if ( params . limit ) queryParams . append ( "limit" , params . limit . toString ( ) ) ;
109114
@@ -137,7 +142,6 @@ export const appointmentApi = createApi({
137142 async onQueryStarted ( { id } , { dispatch, queryFulfilled } ) {
138143 try {
139144 await queryFulfilled ;
140- cacheUtils . appointments . clearAll ( ) ;
141145 } catch ( error ) {
142146 console . error ( "Failed to update appointment:" , error ) ;
143147 }
@@ -153,7 +157,6 @@ export const appointmentApi = createApi({
153157 async onQueryStarted ( id , { dispatch, queryFulfilled } ) {
154158 try {
155159 await queryFulfilled ;
156- cacheUtils . appointments . clearAll ( ) ;
157160 } catch ( error ) {
158161 console . error ( "Failed to delete appointment:" , error ) ;
159162 }
@@ -174,7 +177,6 @@ export const appointmentApi = createApi({
174177 async onQueryStarted ( { id } , { dispatch, queryFulfilled } ) {
175178 try {
176179 await queryFulfilled ;
177- cacheUtils . appointments . clearAll ( ) ;
178180 } catch ( error ) {
179181 console . error ( "Failed to reschedule appointment:" , error ) ;
180182 }
@@ -198,4 +200,4 @@ export const {
198200} = appointmentApi ;
199201
200202// Legacy compatibility exports
201- export const useCreateQuickAppointmentMutation = useCreateAppointmentMutation ;
203+
0 commit comments