be able to unfix a boat damage for tech
CI/CD Pipeline / test (push) Successful in 26m39s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2026-05-24 10:38:54 +02:00
parent c862b28552
commit 743b296895
3 changed files with 73 additions and 0 deletions
+46
View File
@@ -271,6 +271,52 @@ ORDER BY created_at DESC
Ok(())
}
pub async fn unfix(&self, db: &SqlitePool, tech_user: &User) -> Result<(), String> {
if self.user_id_verified.is_some() {
return Err("Reparatur wurde bereits verifiziert und kann nicht mehr rückgängig gemacht werden.".into());
}
if self.user_id_fixed.is_none() {
return Err("Reparatur wurde noch nicht eingetragen.".into());
}
let boat = Boat::find_by_id(db, self.boat_id as i32)
.await
.ok_or("Boot gibt's ned")?;
Log::create(
db,
format!("Unfix boat damage id={} by user {:?}", self.id, tech_user),
)
.await;
sqlx::query!(
"UPDATE boat_damage SET user_id_fixed=NULL, fixed_at=NULL WHERE id=?",
self.id
)
.execute(db)
.await
.map_err(|e| e.to_string())?;
let technicals =
User::all_with_role(db, &Role::find_by_name(db, "tech").await.unwrap()).await;
for technical in technicals {
Notification::create(
db,
&technical,
&format!(
"{} hat die Reparatur des Bootschadens '{}' beim Boot '{}' als fehlerhaft eingetragen zurückgesetzt.",
tech_user.name, self.desc, boat.name,
),
"Bootsschaden-Reparatur rückgängig gemacht",
None,
None,
)
.await;
}
Ok(())
}
pub async fn verified(
&self,
db: &SqlitePool,