don't allow to delete an event if someone is registered
This commit is contained in:
parent
d819462b0d
commit
02e1f77f65
@ -240,11 +240,29 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
.unwrap(); //Okay, as planned_event can only be created with proper DB backing
|
||||
}
|
||||
|
||||
pub async fn delete(&self, db: &SqlitePool) {
|
||||
pub async fn delete(&self, db: &SqlitePool) -> Result<(), String> {
|
||||
if Registration::all_rower(db, self.trip_details_id)
|
||||
.await
|
||||
.len()
|
||||
> 0
|
||||
{
|
||||
return Err(
|
||||
"Event kann nicht gelöscht werden, weil mind. 1 Ruderer angemeldet ist.".into(),
|
||||
);
|
||||
}
|
||||
if Registration::all_cox(db, self.trip_details_id).await.len() > 0 {
|
||||
return Err(
|
||||
"Event kann nicht gelöscht werden, weil mind. 1 Steuerperson angemeldet ist."
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
sqlx::query!("DELETE FROM planned_event WHERE id = ?", self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap(); //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_ics_feed(db: &SqlitePool) -> String {
|
||||
|
Loading…
Reference in New Issue
Block a user