be able to unfix a boat damage for tech #1217

Merged
philipp merged 1 commits from unfix-damage into main 2026-05-24 10:43:58 +02:00
3 changed files with 73 additions and 0 deletions
Showing only changes of commit 743b296895 - Show all commits
+46
View File
@@ -271,6 +271,52 @@ ORDER BY created_at DESC
Ok(()) 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( pub async fn verified(
&self, &self,
db: &SqlitePool, db: &SqlitePool,
+20
View File
@@ -152,6 +152,25 @@ pub struct FormBoatDamageVerified<'r> {
desc: &'r str, desc: &'r str,
} }
#[post("/<boatdamage_id>/unfix")]
async fn unfix(
db: &State<SqlitePool>,
boatdamage_id: i32,
techuser: TechUser,
) -> Flash<Redirect> {
let Some(boatdamage) = BoatDamage::find_by_id(db, boatdamage_id).await else {
return Flash::error(Redirect::to("/boatdamage"), "Bootsschaden nicht gefunden.");
};
let user: User = techuser.into_inner();
match boatdamage.unfix(db, &user).await {
Ok(_) => Flash::success(
Redirect::to("/boatdamage"),
"Reparatur wurde zurückgesetzt.",
),
Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Fehler: {e}")),
}
}
#[post("/<boatdamage_id>/verified", data = "<data>")] #[post("/<boatdamage_id>/verified", data = "<data>")]
async fn verified<'r>( async fn verified<'r>(
db: &State<SqlitePool>, db: &State<SqlitePool>,
@@ -176,6 +195,7 @@ pub fn routes() -> Vec<Route> {
index_kiosk, index_kiosk,
create, create,
fixed, fixed,
unfix,
verified, verified,
create_from_kiosk create_from_kiosk
] ]
+7
View File
@@ -55,6 +55,13 @@
</small> </small>
{% if boatdamage.fixed_at %} {% if boatdamage.fixed_at %}
<small class="block text-gray-600 dark:text-gray-100">Repariert von {{ boatdamage.user_fixed.name }} am/um {{ boatdamage.fixed_at | date(format='%d.%m.%Y (%H:%M)') }}</small> <small class="block text-gray-600 dark:text-gray-100">Repariert von {{ boatdamage.user_fixed.name }} am/um {{ boatdamage.fixed_at | date(format='%d.%m.%Y (%H:%M)') }}</small>
{% if loggedin_user and "tech" in loggedin_user.roles and not boatdamage.verified_at %}
<form action="/boatdamage/{{ boatdamage.id }}/unfix" method="post" class="mt-1">
<input type="submit"
class="btn btn-dark text-sm"
value="Reparatur rückgängig" />
</form>
{% endif %}
{% else %} {% else %}
{% if loggedin_user and loggedin_user.allowed_to_steer %} {% if loggedin_user and loggedin_user.allowed_to_steer %}
<form action="/boatdamage/{{ boatdamage.id }}/fixed" <form action="/boatdamage/{{ boatdamage.id }}/fixed"