new newbie flag
This commit is contained in:
@@ -48,6 +48,7 @@ pub struct TripUpdate<'a> {
|
||||
pub notes: Option<&'a str>,
|
||||
pub trip_type: Option<i64>, //TODO: Move to `TripType`
|
||||
pub is_locked: bool,
|
||||
pub allow_guests: bool,
|
||||
}
|
||||
|
||||
impl TripUpdate<'_> {
|
||||
@@ -228,6 +229,13 @@ WHERE day=?
|
||||
let tripdetails = TripDetails::find_by_id(db, trip_details_id).await.unwrap();
|
||||
let was_already_cancelled = tripdetails.cancelled();
|
||||
|
||||
if tripdetails.allow_guests && !update.allow_guests {
|
||||
let rowers = Registration::all_rower(db, trip_details_id).await;
|
||||
if rowers.iter().any(|r| r.is_newbie) {
|
||||
return Err(TripUpdateError::NeulingAlreadyRegistered);
|
||||
}
|
||||
}
|
||||
|
||||
let is_locked = if update.cancelled() {
|
||||
false
|
||||
} else {
|
||||
@@ -235,11 +243,12 @@ WHERE day=?
|
||||
};
|
||||
|
||||
sqlx::query!(
|
||||
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ?, is_locked = ? WHERE id = ?",
|
||||
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ?, is_locked = ?, allow_guests = ? WHERE id = ?",
|
||||
update.max_people,
|
||||
update.notes,
|
||||
update.trip_type,
|
||||
is_locked,
|
||||
update.allow_guests,
|
||||
trip_details_id
|
||||
)
|
||||
.execute(db)
|
||||
@@ -407,6 +416,7 @@ pub enum TripUpdateError {
|
||||
NotYourTrip,
|
||||
TripDetailsDoesNotExist,
|
||||
TripTypeNotAllowed,
|
||||
NeulingAlreadyRegistered,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -540,6 +550,7 @@ mod test {
|
||||
notes: None,
|
||||
trip_type: None,
|
||||
is_locked: false,
|
||||
allow_guests: false,
|
||||
};
|
||||
|
||||
assert!(Trip::update_own(&pool, &update).await.is_ok());
|
||||
@@ -568,6 +579,7 @@ mod test {
|
||||
notes: None,
|
||||
trip_type: Some(1),
|
||||
is_locked: false,
|
||||
allow_guests: false,
|
||||
};
|
||||
assert!(Trip::update_own(&pool, &update).await.is_ok());
|
||||
|
||||
@@ -596,6 +608,7 @@ mod test {
|
||||
notes: None,
|
||||
trip_type: None,
|
||||
is_locked: false,
|
||||
allow_guests: false,
|
||||
};
|
||||
assert!(Trip::update_own(&pool, &update).await.is_err());
|
||||
assert_eq!(trip.max_people, 1);
|
||||
|
||||
Reference in New Issue
Block a user