Skip to content

Commit 0022027

Browse files
committed
feat: allow other users to reschedule
1 parent cd71ec8 commit 0022027

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/handlers/appointments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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}",

src/hospitals/appointments.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff 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),

0 commit comments

Comments
 (0)