Compare commits
No commits in common. "fc49e6c9772c8718bec3091cf8f28e68ecd00881" and "82865799cee61385b018ccaec0afdcf12c1aca85" have entirely different histories.
fc49e6c977
...
82865799ce
@ -119,10 +119,6 @@ ORDER BY created_at DESC
|
|||||||
|
|
||||||
pub async fn create(db: &SqlitePool, boatdamage: BoatDamageToAdd<'_>) -> Result<(), String> {
|
pub async fn create(db: &SqlitePool, boatdamage: BoatDamageToAdd<'_>) -> Result<(), String> {
|
||||||
Log::create(db, format!("New boat damage: {boatdamage:?}")).await;
|
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!(
|
sqlx::query!(
|
||||||
"INSERT INTO boat_damage(boat_id, desc, user_id_created, lock_boat) VALUES (?,?,?, ?)",
|
"INSERT INTO boat_damage(boat_id, desc, user_id_created, lock_boat) VALUES (?,?,?, ?)",
|
||||||
@ -135,11 +131,6 @@ ORDER BY created_at DESC
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.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 =
|
let technicals =
|
||||||
User::all_with_role(db, &Role::find_by_name(db, "tech").await.unwrap()).await;
|
User::all_with_role(db, &Role::find_by_name(db, "tech").await.unwrap()).await;
|
||||||
for technical in technicals {
|
for technical in technicals {
|
||||||
@ -153,7 +144,10 @@ ORDER BY created_at DESC
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.name,
|
.name,
|
||||||
boat.name,
|
Boat::find_by_id(db, boatdamage.boat_id as i32)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.name,
|
||||||
boatdamage.desc
|
boatdamage.desc
|
||||||
),
|
),
|
||||||
"Neuer Bootsschaden angelegt",
|
"Neuer Bootsschaden angelegt",
|
||||||
@ -273,41 +267,35 @@ ORDER BY created_at DESC
|
|||||||
pub async fn verified(
|
pub async fn verified(
|
||||||
&self,
|
&self,
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
boat_form: BoatDamageVerified<'_>,
|
boat: BoatDamageVerified<'_>,
|
||||||
) -> Result<(), String> {
|
) -> 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 {
|
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());
|
return Err("You are not allowed to verify the boat!".into());
|
||||||
}
|
}
|
||||||
} else {
|
} 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());
|
return Err("Could not find user".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(boat) = Boat::find_by_id(db, self.boat_id as i32).await else {
|
Log::create(db, format!("Verified boat damage: {boat:?}")).await;
|
||||||
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;
|
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE boat_damage SET desc=?, user_id_verified=?, verified_at=CURRENT_TIMESTAMP WHERE id=?",
|
"UPDATE boat_damage SET desc=?, user_id_verified=?, verified_at=CURRENT_TIMESTAMP WHERE id=?",
|
||||||
boat_form.desc,
|
boat.desc,
|
||||||
boat_form.user_id_verified,
|
boat.user_id_verified,
|
||||||
self.id
|
self.id
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(db)
|
||||||
.await.map_err(|e| e.to_string())?;
|
.await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
if boat_form.user_id_verified != self.user_id_created as i32 {
|
if boat.user_id_verified != self.user_id_created as i32 {
|
||||||
let user_verified = User::find_by_id(db, boat_form.user_id_verified)
|
let user_verified = User::find_by_id(db, boat.user_id_verified).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let user_created = User::find_by_id(db, self.user_id_created as i32)
|
let user_created = User::find_by_id(db, self.user_id_created as i32)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let boat = Boat::find_by_id(db, self.boat_id as i32).await.unwrap();
|
||||||
|
|
||||||
if user_verified.id == self.user_id_fixed.unwrap() {
|
if user_verified.id == self.user_id_fixed.unwrap() {
|
||||||
Notification::create(
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user