allow no cox in 1x; require them in >2x

This commit is contained in:
philipp 2023-10-31 20:57:05 +01:00
parent 5a596132ab
commit d9c7c218bc
2 changed files with 69 additions and 15 deletions

View File

@ -124,21 +124,33 @@ function setMaxAmountRowers(rowers: number, isShipmasterSteering='false') {
} }
} }
let only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering'); //let only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
if(only_steering) { //if(only_steering) {
if(isShipmasterSteering == 'true') { // if(isShipmasterSteering == 'true') {
only_steering.removeAttribute('disabled'); // only_steering.removeAttribute('disabled');
only_steering.setAttribute('checked', 'true'); // only_steering.setAttribute('checked', 'true');
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('hidden'); // only_steering.parentElement?.parentElement?.parentElement?.classList.remove('hidden');
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('md:block'); // only_steering.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50'); // only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
} else { // } else {
only_steering.setAttribute('disabled', 'disabled'); // only_steering.setAttribute('disabled', 'disabled');
only_steering.removeAttribute('checked'); // only_steering.removeAttribute('checked');
only_steering.parentElement?.parentElement?.parentElement?.classList.add('hidden'); // only_steering.parentElement?.parentElement?.parentElement?.classList.add('hidden');
only_steering.parentElement?.parentElement?.parentElement?.classList.add('md:block'); // only_steering.parentElement?.parentElement?.parentElement?.classList.add('md:block');
only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50'); // only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
} // }
//}
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-newrowerjs');
let steering_person = <HTMLElement>document.querySelector('#steering_person-newrowerjs');
if (rowers == 1){
shipmaster.parentNode.classList.add('hidden');
steering_person.parentNode.classList.add('hidden');
}else{
shipmaster.parentNode.classList.remove('hidden');
shipmaster.setAttribute('required', 'required');
steering_person.parentNode.classList.remove('hidden');
steering_person.setAttribute('required', 'required');
} }
} }
} }

View File

@ -180,6 +180,48 @@ ORDER BY departure DESC
return Err(LogbookCreateError::BoatNotFound); 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 { if boat.is_locked(db).await {
return Err(LogbookCreateError::BoatLocked); return Err(LogbookCreateError::BoatLocked);
} }