From 64f3596132b70aa215c09ac6834845ce29e95ce9 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 21 May 2024 20:43:05 +0200 Subject: [PATCH] remove notificatoin about canceled trip if cancelation has been canceled --- src/model/notification.rs | 10 ++++++++++ src/model/trip.rs | 6 ++++++ src/model/tripdetails.rs | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/src/model/notification.rs b/src/model/notification.rs index bf920cb..fedc3b3 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -154,4 +154,14 @@ ORDER BY read_at DESC, created_at DESC; } } } + + pub(crate) async fn delete_by_action(db: &sqlx::Pool, action: &str) { + sqlx::query!( + "DELETE FROM notification WHERE action_after_reading=? and read_at = null", + action + ) + .execute(db) + .await + .unwrap(); + } } diff --git a/src/model/trip.rs b/src/model/trip.rs index 2f95287..704c4b9 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -232,6 +232,12 @@ WHERE day=? .await; } } + } else { + 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(); diff --git a/src/model/tripdetails.rs b/src/model/tripdetails.rs index d505dcb..df1238e 100644 --- a/src/model/tripdetails.rs +++ b/src/model/tripdetails.rs @@ -77,6 +77,12 @@ WHERE day = ? AND planned_starting_time = ? return; } + if self.max_people == 0 { + // Cox cancelled event, thus it's probably bad weather. Don't bother with sending + // notifications + return; + } + if Trip::find_by_trip_details(db, self.id).await.is_none() { // This trip_details belongs to a planned_event, no need to do anything return; -- 2.45.2