Merge pull request 'don't notify cancelled trips' (#713) from dont-notify-cancelled-trips into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m46s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 8m14s

Reviewed-on: #713
This commit is contained in:
philipp 2024-08-27 09:25:16 +02:00
commit f968d5d03b
2 changed files with 29 additions and 18 deletions

View File

@ -77,23 +77,30 @@ impl Trip {
.await; .await;
if same_starting_datetime.len() > 1 { if same_starting_datetime.len() > 1 {
for notify in same_starting_datetime { for notify in same_starting_datetime {
if notify.id != trip_details.id { // don't notify oneself
// notify everyone except oneself if notify.id == trip_details.id {
if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await { continue;
let user = User::find_by_id(db, trip.cox_id as i32).await.unwrap(); }
Notification::create(
db, // don't notify people who have cancelled their trip
&user, if notify.cancelled(db) {
&format!( continue;
"{} hat eine Ausfahrt zur selben Zeit ({} um {}) wie du erstellt", }
cox.user.name, trip.day, trip.planned_starting_time
), if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await {
"Neue Ausfahrt zur selben Zeit", let user = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
None, Notification::create(
None, db,
) &user,
.await; &format!(
} "{} hat eine Ausfahrt zur selben Zeit ({} um {}) wie du erstellt",
cox.user.name, trip.day, trip.planned_starting_time
),
"Neue Ausfahrt zur selben Zeit",
None,
None,
)
.await;
} }
} }
} }

View File

@ -77,6 +77,10 @@ WHERE day = ? AND planned_starting_time = ?
.await.unwrap() .await.unwrap()
} }
pub fn cancelled(&self, db: &SqlitePool) -> bool {
self.max_people == 0
}
/// This function is called when a person registers to a trip or when the cox changes the /// This function is called when a person registers to a trip or when the cox changes the
/// amount of free places. /// amount of free places.
pub async fn check_free_spaces(&self, db: &SqlitePool) { pub async fn check_free_spaces(&self, db: &SqlitePool) {
@ -85,7 +89,7 @@ WHERE day = ? AND planned_starting_time = ?
return; return;
} }
if self.max_people == 0 { if self.cancelled(db) {
// Cox cancelled event, thus it's probably bad weather. Don't bother with sending // Cox cancelled event, thus it's probably bad weather. Don't bother with sending
// notifications // notifications
return; return;