send creator of boatdamage notification when it has been repaired
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
philipp 2024-04-17 12:44:31 +02:00
parent d0830e4631
commit 22d499d38b
2 changed files with 60 additions and 13 deletions

View File

@ -235,19 +235,31 @@ ORDER BY created_at DESC
} }
} }
Notification::create( if boat_damage.user_id_fixed != self.user_id_created as i32 {
db, let user_fixed = User::find_by_id(db, boat_damage.user_id_fixed)
&User::find_by_id(db, boat_damage.user_id_fixed)
.await .await
.unwrap(), .unwrap();
&format!( let user_created = User::find_by_id(db, self.user_id_created as i32)
"Du hat den Bootschaden '{}' beim Boot '{}' repariert. Danke für deine Hilfe!", .await
boat_damage.desc, boat.name, .unwrap();
),
"Bootsschaden repariert", // Boatdamage is also directly verified, if a tech has repaired it. We don't want to
None, // send 2 notifications.
) if !user_fixed.has_role(db, "tech").await {
.await; Notification::create(
db,
&user_created,
&format!(
"{} hat den von dir eingetragenen Bootschaden '{}' beim Boot '{}' repariert. Dieser muss nun noch von unseren Bootswarten bestätigt werden.",
user_fixed.name,
boat_damage.desc, boat.name,
),
"Bootsschaden repariert",
None,
)
.await;
}
}
Ok(()) Ok(())
} }
@ -277,6 +289,42 @@ ORDER BY created_at DESC
) )
.execute(db) .execute(db)
.await.map_err(|e| e.to_string())?; .await.map_err(|e| e.to_string())?;
if boat.user_id_verified != self.user_id_created as i32 {
let user_verified = User::find_by_id(db, boat.user_id_verified).await.unwrap();
let user_created = User::find_by_id(db, self.user_id_created as i32)
.await
.unwrap();
let boat = Boat::find_by_id(db, self.boat_id as i32).await.unwrap();
if user_verified.id == self.user_id_fixed.unwrap() {
Notification::create(
db,
&user_created,
&format!(
"{} hat den von dir eingetragenen Bootschaden '{}' beim Boot '{}' repariert und verifiziert.",
user_verified.name,
self.desc, boat.name,
),
"Bootsschaden repariert & verifiziert",
None,
)
.await;
} else {
Notification::create(
db,
&user_created,
&format!(
"{} hat verifiziert, dass der von dir eingetragenen Bootschaden '{}' beim Boot '{}' korrekt repariert wurde.",
user_verified.name,
self.desc, boat.name,
),
"Bootsschaden verifiziert",
None,
).await;
}
}
Ok(()) Ok(())
} }
} }

View File

@ -145,7 +145,6 @@ impl Fairing for Usage {
{ {
let config = req.rocket().state::<Config>().unwrap(); let config = req.rocket().state::<Config>().unwrap();
let Ok(mut file) = OpenOptions::new() let Ok(mut file) = OpenOptions::new()
.write(true)
.append(true) .append(true)
.open(config.usage_log_path.clone()) .open(config.usage_log_path.clone())
else { else {