forked from Ruderverein-Donau-Linz/rowt
allow no cox in 1x; require them in >2x
This commit is contained in:
@ -180,6 +180,48 @@ ORDER BY departure DESC
|
||||
return Err(LogbookCreateError::BoatNotFound);
|
||||
};
|
||||
|
||||
if let Ok(log_to_finalize) = TryInto::<LogToFinalize>::try_into(log.clone()) {
|
||||
//TODO: fix clone() above
|
||||
|
||||
if !boat.shipmaster_allowed(created_by_user).await {
|
||||
return Err(LogbookCreateError::UserNotAllowedToUseBoat);
|
||||
}
|
||||
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
|
||||
let inserted_row = sqlx::query!(
|
||||
"INSERT INTO logbook(boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING id",
|
||||
log.boat_id,
|
||||
log.shipmaster,
|
||||
log.steering_person,
|
||||
log.shipmaster_only_steering,
|
||||
log.departure,
|
||||
log.arrival,
|
||||
log.destination,
|
||||
log.distance_in_km,
|
||||
log.comments,
|
||||
log.logtype
|
||||
)
|
||||
.fetch_one(&mut tx)
|
||||
.await.unwrap().id;
|
||||
|
||||
let logbook = Logbook::find_by_id(db, inserted_row as i32).await.unwrap(); //ok
|
||||
|
||||
return match logbook
|
||||
.home_with_transaction(&mut tx, created_by_user, log_to_finalize)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
tx.commit().await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
Err(a) => Err(a.into()),
|
||||
};
|
||||
}
|
||||
if log.arrival.is_some() {
|
||||
return Err(LogbookCreateError::ArrivalSetButNotRemainingTwo);
|
||||
}
|
||||
|
||||
if boat.is_locked(db).await {
|
||||
return Err(LogbookCreateError::BoatLocked);
|
||||
}
|
||||
|
Reference in New Issue
Block a user