Compare commits
No commits in common. "42a1579cd1d0c688546315eb87ef3517b048dba3" and "c5af1e4cf8deacdbcc2f81b3c27eeec0c1c68f70" have entirely different histories.
42a1579cd1
...
c5af1e4cf8
@ -5,8 +5,6 @@ use rocket::FromForm;
|
|||||||
use sqlx::{FromRow, SqlitePool};
|
use sqlx::{FromRow, SqlitePool};
|
||||||
|
|
||||||
use super::log::Log;
|
use super::log::Log;
|
||||||
use super::notification::Notification;
|
|
||||||
use super::role::Role;
|
|
||||||
|
|
||||||
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
||||||
pub struct BoatDamage {
|
pub struct BoatDamage {
|
||||||
@ -126,125 +124,35 @@ ORDER BY created_at DESC
|
|||||||
.execute(db)
|
.execute(db)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.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 {
|
|
||||||
if technical.id as i32 != boatdamage.user_id_created {
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&technical,
|
|
||||||
&format!(
|
|
||||||
"{} hat einen neuen Bootschaden für Boot '{}' angelegt: {}",
|
|
||||||
User::find_by_id(db, boatdamage.user_id_created)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.name,
|
|
||||||
Boat::find_by_id(db, boatdamage.boat_id as i32)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.name,
|
|
||||||
boatdamage.desc
|
|
||||||
),
|
|
||||||
"Neuer Bootsschaden angelegt",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&User::find_by_id(db, boatdamage.user_id_created)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
&format!(
|
|
||||||
"Du hat einen neuen Bootschaden für Boot '{}' angelegt: {}",
|
|
||||||
Boat::find_by_id(db, boatdamage.boat_id as i32)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.name,
|
|
||||||
boatdamage.desc
|
|
||||||
),
|
|
||||||
"Neuer Bootsschaden angelegt",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fixed(
|
pub async fn fixed(&self, db: &SqlitePool, boat: BoatDamageFixed<'_>) -> Result<(), String> {
|
||||||
&self,
|
Log::create(db, format!("Fixed boat damage: {boat:?}")).await;
|
||||||
db: &SqlitePool,
|
|
||||||
boat_damage: BoatDamageFixed<'_>,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
Log::create(db, format!("Fixed boat damage: {boat_damage:?}")).await;
|
|
||||||
|
|
||||||
let boat = Boat::find_by_id(db, self.boat_id as i32).await.unwrap();
|
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE boat_damage SET desc=?, user_id_fixed=?, fixed_at=CURRENT_TIMESTAMP WHERE id=?",
|
"UPDATE boat_damage SET desc=?, user_id_fixed=?, fixed_at=CURRENT_TIMESTAMP WHERE id=?",
|
||||||
boat_damage.desc,
|
boat.desc,
|
||||||
boat_damage.user_id_fixed,
|
boat.user_id_fixed,
|
||||||
self.id
|
self.id
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(db)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let user = User::find_by_id(db, boat_damage.user_id_fixed)
|
let user = User::find_by_id(db, boat.user_id_fixed).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
if user.has_role(db, "tech").await {
|
if user.has_role(db, "tech").await {
|
||||||
return self
|
return self
|
||||||
.verified(
|
.verified(
|
||||||
db,
|
db,
|
||||||
BoatDamageVerified {
|
BoatDamageVerified {
|
||||||
desc: boat_damage.desc,
|
desc: boat.desc,
|
||||||
user_id_verified: user.id as i32,
|
user_id_verified: user.id as i32,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let technicals =
|
|
||||||
User::all_with_role(db, &Role::find_by_name(db, "tech").await.unwrap()).await;
|
|
||||||
for technical in technicals {
|
|
||||||
if technical.id as i32 != boat_damage.user_id_fixed {
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&technical,
|
|
||||||
&format!(
|
|
||||||
"{} hat den Bootschaden '{}' beim Boot '{}' repariert. Könntest du das bei Gelegenheit verifizieren?",
|
|
||||||
User::find_by_id(db, boat_damage.user_id_fixed)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.name,
|
|
||||||
boat_damage.desc,
|
|
||||||
boat.name,
|
|
||||||
),
|
|
||||||
"Bootsschaden repariert",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&User::find_by_id(db, boat_damage.user_id_fixed)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
&format!(
|
|
||||||
"Du hat den Bootschaden '{}' beim Boot '{}' repariert. Danke für deine Hilfe!",
|
|
||||||
boat_damage.desc, boat.name,
|
|
||||||
),
|
|
||||||
"Bootsschaden repariert",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user