Compare commits

..

No commits in common. "b8463122d6ca169819186dea07f8acfb9d46294c" and "76f08905ab256051f0fab4a6eafa2cb801bd093b" have entirely different histories.

View File

@ -119,10 +119,6 @@ ORDER BY created_at DESC
pub async fn create(db: &SqlitePool, boatdamage: BoatDamageToAdd<'_>) -> Result<(), String> {
Log::create(db, format!("New boat damage: {boatdamage:?}")).await;
let Some(boat) = Boat::find_by_id(db, boatdamage.boat_id as i32).await else {
return Err("Boot gibt's ned".into());
};
let was_unusable_before = boat.is_locked(db).await;
sqlx::query!(
"INSERT INTO boat_damage(boat_id, desc, user_id_created, lock_boat) VALUES (?,?,?, ?)",
@ -135,11 +131,6 @@ ORDER BY created_at DESC
.await
.map_err(|e| e.to_string())?;
if !was_unusable_before && boat.is_locked(db).await {
let cox = Role::find_by_name(db, "cox").await.unwrap();
Notification::create_for_role(db, &cox, &format!("Liebe Steuerberechtigte, bitte beachten, dass {} bis auf weiteres aufgrund von Reparaturarbeiten gesperrt ist.", boat.name), "Boot gesperrt", None).await;
}
let technicals =
User::all_with_role(db, &Role::find_by_name(db, "tech").await.unwrap()).await;
for technical in technicals {
@ -153,7 +144,10 @@ ORDER BY created_at DESC
.await
.unwrap()
.name,
boat.name,
Boat::find_by_id(db, boatdamage.boat_id as i32)
.await
.unwrap()
.name,
boatdamage.desc
),
"Neuer Bootsschaden angelegt",
@ -273,41 +267,35 @@ ORDER BY created_at DESC
pub async fn verified(
&self,
db: &SqlitePool,
boat_form: BoatDamageVerified<'_>,
boat: BoatDamageVerified<'_>,
) -> Result<(), String> {
if let Some(verifier) = User::find_by_id(db, boat_form.user_id_verified).await {
if let Some(verifier) = User::find_by_id(db, boat.user_id_verified).await {
if !verifier.has_role(db, "tech").await {
Log::create(db, format!("User {verifier:?} tried to verify boat {boat_form:?}. The user is no tech. Manually craftted request?")).await;
Log::create(db, format!("User {verifier:?} tried to verify boat {boat:?}. The user is no tech. Manually craftted request?")).await;
return Err("You are not allowed to verify the boat!".into());
}
} else {
Log::create(db, format!("Someone tried to verify the boat {boat_form:?} with user_id={} which does not exist. Manually craftted request?", boat_form.user_id_verified)).await;
Log::create(db, format!("Someone tried to verify the boat {boat:?} with user_id={} which does not exist. Manually craftted request?", boat.user_id_verified)).await;
return Err("Could not find user".into());
}
let Some(boat) = Boat::find_by_id(db, self.boat_id as i32).await else {
return Err("Boot gibt's ned".into());
};
let was_unusable_before = boat.is_locked(db).await;
Log::create(db, format!("Verified boat damage: {boat_form:?}")).await;
Log::create(db, format!("Verified boat damage: {boat:?}")).await;
sqlx::query!(
"UPDATE boat_damage SET desc=?, user_id_verified=?, verified_at=CURRENT_TIMESTAMP WHERE id=?",
boat_form.desc,
boat_form.user_id_verified,
boat.desc,
boat.user_id_verified,
self.id
)
.execute(db)
.await.map_err(|e| e.to_string())?;
if boat_form.user_id_verified != self.user_id_created as i32 {
let user_verified = User::find_by_id(db, boat_form.user_id_verified)
.await
.unwrap();
if boat.user_id_verified != self.user_id_created as i32 {
let user_verified = User::find_by_id(db, boat.user_id_verified).await.unwrap();
let user_created = User::find_by_id(db, self.user_id_created as i32)
.await
.unwrap();
let boat = Boat::find_by_id(db, self.boat_id as i32).await.unwrap();
if user_verified.id == self.user_id_fixed.unwrap() {
Notification::create(
@ -337,11 +325,6 @@ ORDER BY created_at DESC
}
}
if was_unusable_before && !boat.is_locked(db).await {
let cox = Role::find_by_name(db, "cox").await.unwrap();
Notification::create_for_role(db, &cox, &format!("Liebe Steuerberechtigte, {} wurde repariert und freut sich ab sofort wieder gerudert zu werden :-)", boat.name), "Boot repariert", None).await;
}
Ok(())
}
}