File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ pub async fn confirm_appointment(
110110 Ok ( ApiResponse :: success ( appt) )
111111}
112112
113- /// Reschedule an appointment. Used by Hospital staff
113+ /// Reschedule an appointment
114114#[ utoipa:: path(
115115 put,
116116 path = "/api/appointments/reschedule/{appointment_id}" ,
Original file line number Diff line number Diff line change @@ -93,14 +93,16 @@ pub fn reschedule_appointment(
9393 user : & User ,
9494 new_time : DateTime < Utc > ,
9595) -> Result < Appointment , AppError > {
96- if user. role != Role :: Hospital {
97- return Err ( AppError :: Unauthorized (
98- "Only hospitals can reschedule appointments" . into ( ) ,
99- ) ) ;
96+ match user. role {
97+ Role :: Hospital => {
98+ assert_hospital_owns_appointment ( conn, appointment_id, user. id ) ?;
99+ }
100+ Role :: Donor | Role :: Patient => {
101+ assert_user_owns_appointment ( conn, appointment_id, user. id ) ?;
102+ }
103+ _ => return Err ( AppError :: Unauthorized ( "Invalid role" . into ( ) ) ) ,
100104 }
101105
102- assert_hospital_owns_appointment ( conn, appointment_id, user. id ) ?;
103-
104106 diesel:: update ( appointments:: table. find ( appointment_id) )
105107 . set ( (
106108 appointments:: status. eq ( AppointmentStatusEnum :: Rescheduled ) ,
You can’t perform that action at this time.
0 commit comments