Merge pull request 'Merge pull request 'clean families; Fixes #1171' (#1212) from clean-families into main' (#1216) from unfix-damage into staging
Reviewed-on: #1216
This commit was merged in pull request #1216.
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user