add test for cancel-event-notification
This commit is contained in:
@ -14,7 +14,7 @@ use super::{notification::Notification, tripdetails::TripDetails, triptype::Trip
|
||||
pub struct Event {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
planned_amount_cox: i64,
|
||||
pub(crate) planned_amount_cox: i64,
|
||||
trip_details_id: i64,
|
||||
pub planned_starting_time: String,
|
||||
pub(crate) max_people: i64,
|
||||
@ -22,8 +22,8 @@ pub struct Event {
|
||||
pub notes: Option<String>,
|
||||
pub allow_guests: bool,
|
||||
trip_type_id: Option<i64>,
|
||||
always_show: bool,
|
||||
is_locked: bool,
|
||||
pub(crate) always_show: bool,
|
||||
pub(crate) is_locked: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
@ -73,7 +73,7 @@ FROM user_trip WHERE trip_details_id = {}
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub async fn all_cox(db: &SqlitePool, trip_details_id: i64) -> Vec<Registration> {
|
||||
pub async fn all_cox(db: &SqlitePool, event_id: i64) -> Vec<Registration> {
|
||||
//TODO: switch to join
|
||||
sqlx::query!(
|
||||
"
|
||||
@ -82,7 +82,7 @@ SELECT
|
||||
(SELECT created_at FROM user WHERE cox_id = id) as registered_at
|
||||
FROM trip WHERE planned_event_id = ?
|
||||
",
|
||||
trip_details_id
|
||||
event_id
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
@ -159,7 +159,7 @@ WHERE day=?",
|
||||
cox_needed: event.planned_amount_cox > cox.len() as i64,
|
||||
cox,
|
||||
rower: Registration::all_rower(db, event.trip_details_id).await,
|
||||
event: event,
|
||||
event,
|
||||
trip_type,
|
||||
});
|
||||
}
|
||||
@ -195,11 +195,27 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
is_rower.amount > 0
|
||||
}
|
||||
|
||||
pub async fn find_by_trip_details(db: &SqlitePool, tripdetails_id: i64) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT planned_event.id, planned_event.name, planned_amount_cox, trip_details_id, planned_starting_time, always_show, max_people, day, notes, allow_guests, trip_type_id, is_locked
|
||||
FROM planned_event
|
||||
INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id
|
||||
WHERE trip_details.id=?
|
||||
",
|
||||
tripdetails_id
|
||||
)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
db: &SqlitePool,
|
||||
name: &str,
|
||||
planned_amount_cox: i32,
|
||||
trip_details: TripDetails,
|
||||
trip_details: &TripDetails,
|
||||
) {
|
||||
sqlx::query!(
|
||||
"INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)",
|
||||
@ -257,7 +273,7 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
),
|
||||
"Absage Ausfahrt",
|
||||
None,
|
||||
Some(&format!("remove_trip_by_planned_event:{}", self.id)),
|
||||
Some(&format!("remove_trip_by_event:{}", self.id)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -295,11 +311,7 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
&format!("remove_user_trip_with_trip_details_id:{}", tripdetails.id),
|
||||
)
|
||||
.await;
|
||||
Notification::delete_by_action(
|
||||
db,
|
||||
&format!("remove_trip_by_planned_event:{}", self.id),
|
||||
)
|
||||
.await;
|
||||
Notification::delete_by_action(db, &format!("remove_trip_by_event:{}", self.id)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,7 +391,7 @@ mod test {
|
||||
|
||||
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
Event::create(&pool, "new-event".into(), 2, trip_details).await;
|
||||
Event::create(&pool, "new-event".into(), 2, &trip_details).await;
|
||||
|
||||
let res = Event::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
assert_eq!(res.len(), 2);
|
||||
|
Reference in New Issue
Block a user