show notification to vorstand if boat entry with 'externes boot' or on multiple days is entered
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
2024-04-15 22:03:20 +02:00
parent 8315a27ea8
commit 219b80377d
4 changed files with 69 additions and 4 deletions

View File

@ -5,7 +5,9 @@ use rocket::FromForm;
use serde::Serialize;
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
use super::{boat::Boat, log::Log, notification::Notification, rower::Rower, user::User};
use super::{
boat::Boat, log::Log, notification::Notification, role::Role, rower::Rower, user::User,
};
#[derive(FromRow, Serialize, Clone, Debug)]
pub struct Logbook {
@ -560,6 +562,31 @@ ORDER BY departure DESC
.execute(db.deref_mut())
.await.unwrap(); //TODO: fixme
let duration = arr - dep;
if duration.num_days() > 0 {
let vorstand = Role::find_by_name_tx(db, "Vorstand").await.unwrap();
Notification::create_for_role_tx(
db,
&vorstand,
&format!("'{}' hat eine mehrtägige Ausfahrt vom {} bis {} eingetragen ({} km; Ziel: {}; Anmerkungen: {}). Falls das nicht stimmen sollte, bitte nachhaken.",user.name,log.departure, log.arrival, log.distance_in_km, log.destination, log.comments.clone().unwrap_or("".into())),
"Mehrtägige Ausfahrt eingetragen",
None,
).await;
}
if boat.name == "Externes Boot" {
let vorstand = Role::find_by_name_tx(db, "Vorstand").await.unwrap();
Notification::create_for_role_tx(
db,
&vorstand,
&format!("'{}' hat eine Ausfahrt mit *Externem Boot* am {} eingetragen ({} km; Ziel: {}; Anmerkungen: {}). Falls das nicht stimmen sollte, bitte nachhaken.",user.name,log.departure,log.distance_in_km, log.destination, log.comments.unwrap_or("".into())),
"Ausfahrt mit externem Boot eingetragen",
None,
).await;
}
Ok(())
}