Skip to content

Commit

Permalink
Fix error on deleting in-use event position
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Oct 26, 2024
1 parent c4233c8 commit 2c3be97
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
34 changes: 30 additions & 4 deletions vzdv-site/src/endpoints/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,40 @@ async fn post_delete_position(
.fetch_optional(&state.db)
.await?;
if event.is_some() {
// Need to clear out any existing registrations that are using that position
// and then delete any registrations that are now empty.
let mut tx = state.db.begin().await?;
sqlx::query(sql::CLEAR_REGISTRATIONS_FOR_POSITION_1)
.bind(pos_id)
.execute(&mut *tx)
.await?;
sqlx::query(sql::CLEAR_REGISTRATIONS_FOR_POSITION_2)
.bind(pos_id)
.execute(&mut *tx)
.await?;
sqlx::query(sql::CLEAR_REGISTRATIONS_FOR_POSITION_3)
.bind(pos_id)
.execute(&mut *tx)
.await?;
sqlx::query(sql::DELETE_REGISTRATIONS_NOW_EMPTY)
.bind(id)
.execute(&mut *tx)
.await?;
sqlx::query(sql::DELETE_EVENT_POSITION)
.bind(pos_id)
.execute(&mut *tx)
.await?;
tx.commit().await?;
info!(
"{} removed position {pos_id} from {id}",
user_info.unwrap().cid,
);
sqlx::query(sql::DELETE_EVENT_POSITION)
.bind(pos_id)
.execute(&state.db)
.await?;
flashed_messages::push_flashed_message(
session,
flashed_messages::MessageLevel::Info,
"Position deleted",
)
.await?;
Ok(Redirect::to(&format!("/events/{id}")))
} else {
Ok(Redirect::to("/"))
Expand Down
11 changes: 11 additions & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

<hr>

<div class="card shadow mb-3">
<div class="card-body">
<h5 class="card-title">2024-10-26</h5>
<div class="card-text">
<ul>
<li>Fix error when deleting an event position that controllers have already registered for.<li>
</ul>
</div>
</div>
</div>

<div class="card shadow mb-3">
<div class="card-body">
<h5 class="card-title">2024-10-24</h5>
Expand Down
8 changes: 8 additions & 0 deletions vzdv/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ ON CONFLICT DO UPDATE SET
choice_2=$4,
choice_3=$5,
notes=$6";
pub const CLEAR_REGISTRATIONS_FOR_POSITION_1: &str =
"UPDATE event_registration SET choice_1=NULL WHERE choice_1=$1";
pub const CLEAR_REGISTRATIONS_FOR_POSITION_2: &str =
"UPDATE event_registration SET choice_2=NULL WHERE choice_2=$1";
pub const CLEAR_REGISTRATIONS_FOR_POSITION_3: &str =
"UPDATE event_registration SET choice_3=NULL WHERE choice_3=$1";
pub const DELETE_REGISTRATIONS_NOW_EMPTY: &str =
"DELETE from event_registration WHERE event_id=$1 AND choice_1 is NULL AND choice_2 is NULL AND choice_3 is NULL";

pub const GET_EVENT_POSITIONS: &str = "SELECT * FROM event_position WHERE event_id=$1";
pub const INSERT_EVENT_POSITION: &str =
Expand Down

0 comments on commit 2c3be97

Please sign in to comment.