allow cancel of events
This commit is contained in:
@ -137,6 +137,10 @@ WHERE trip.id=?
|
||||
return Err(CoxHelpError::DetailsLocked);
|
||||
}
|
||||
|
||||
if planned_event.max_people == 0 {
|
||||
return Err(CoxHelpError::CanceledEvent);
|
||||
}
|
||||
|
||||
match sqlx::query!(
|
||||
"INSERT INTO trip (cox_id, planned_event_id) VALUES(?, ?)",
|
||||
cox.id,
|
||||
@ -193,6 +197,9 @@ WHERE day=?
|
||||
return Err(TripUpdateError::TripDetailsDoesNotExist); //TODO: Remove?
|
||||
};
|
||||
|
||||
let tripdetails = TripDetails::find_by_id(db, trip_details_id).await.unwrap();
|
||||
let was_already_cancelled = tripdetails.max_people == 0;
|
||||
|
||||
sqlx::query!(
|
||||
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ?, always_show = ?, is_locked = ? WHERE id = ?",
|
||||
max_people,
|
||||
@ -206,7 +213,7 @@ WHERE day=?
|
||||
.await
|
||||
.unwrap(); //Okay, as trip_details can only be created with proper DB backing
|
||||
|
||||
if max_people == 0 {
|
||||
if max_people == 0 && !was_already_cancelled {
|
||||
let rowers = TripWithUserAndType::from(db, trip.clone()).await.rower;
|
||||
for user in rowers {
|
||||
if let Some(user) = User::find_by_name(db, &user.name).await {
|
||||
@ -234,6 +241,14 @@ WHERE day=?
|
||||
}
|
||||
}
|
||||
|
||||
if max_people > 0 && was_already_cancelled {
|
||||
Notification::delete_by_action(
|
||||
db,
|
||||
&format!("remove_user_trip_with_trip_details_id:{}", trip_details_id),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
let trip_details = TripDetails::find_by_id(db, trip_details_id).await.unwrap();
|
||||
trip_details.check_free_spaces(db).await;
|
||||
|
||||
@ -318,6 +333,7 @@ pub enum CoxHelpError {
|
||||
AlreadyRegisteredAsRower,
|
||||
AlreadyRegisteredAsCox,
|
||||
DetailsLocked,
|
||||
CanceledEvent,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
Reference in New Issue
Block a user