only allow realistic values for logbook entries
Some checks failed
CI/CD Pipeline / test (push) Failing after 14m37s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2024-05-22 22:05:03 +02:00
parent 8f5cc70981
commit 93e3e0ef5c
2 changed files with 16 additions and 1 deletions

View File

@ -104,6 +104,7 @@ pub enum LogbookUpdateError {
SteeringPersonNotInRowers,
UserNotAllowedToUseBoat,
OnlyAllowedToEndTripsEndingToday,
TooFast(i64, i64),
}
#[derive(Debug, PartialEq)]
@ -127,6 +128,7 @@ pub enum LogbookCreateError {
ArrivalSetButNotRemainingTwo,
OnlyAllowedToEndTripsEndingToday,
CantChangeHandoperatableStatusForThisBoat,
TooFast(i64, i64),
}
impl From<LogbookUpdateError> for LogbookCreateError {
@ -150,6 +152,7 @@ impl From<LogbookUpdateError> for LogbookCreateError {
LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => {
LogbookCreateError::OnlyAllowedToEndTripsEndingToday
}
LogbookUpdateError::TooFast(km, min) => LogbookCreateError::TooFast(km, min),
}
}
}
@ -517,6 +520,17 @@ ORDER BY departure DESC
if arr.and_utc().timestamp() < dep.and_utc().timestamp() {
return Err(LogbookUpdateError::ArrivalNotAfterDeparture);
}
let duration_in_mins = (arr.and_utc().timestamp() - dep.and_utc().timestamp()) / 60;
// Not possible to row < 1 min / 500 m = < 2 min / km
let possible_distance_km = duration_in_mins / 2;
if log.distance_in_km > possible_distance_km {
return Err(LogbookUpdateError::TooFast(
log.distance_in_km,
duration_in_mins,
));
}
let today = Local::now().date_naive();
let day_diff = today - arr.date();
let day_diff = day_diff.num_days();