vote: Fix logic to hide graph if week is active

The goal is to not display the graph until the active week has been changed, but the logic
retuned early if it wasn't.

Simplify the query and check directly if the current week is the last one, if so do not
show the graph.
This commit is contained in:
trotFunky 2024-07-26 11:29:24 +01:00
parent 5ec38ee44f
commit 4e1b13dc85
3 changed files with 3 additions and 4 deletions

2
Cargo.lock generated
View file

@ -578,7 +578,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]] [[package]]
name = "fabula_votes_server" name = "fabula_votes_server"
version = "1.2.0" version = "1.2.1"
dependencies = [ dependencies = [
"argon2", "argon2",
"blake2", "blake2",

View file

@ -3,7 +3,7 @@ name = "fabula_votes_server"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["trotFunky"] authors = ["trotFunky"]
version = "1.2.0" version = "1.2.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -113,8 +113,7 @@ pub async fn fetch_vote_data(week: u8, mut db: Connection<database::Db>) -> Opti
let vote_count = raw_votes.iter().fold(0, |count, votes| {count + votes.votes}); let vote_count = raw_votes.iter().fold(0, |count, votes| {count + votes.votes});
// Only show the graph if we have all the votes and this is not the last week. // Only show the graph if we have all the votes and this is not the last week.
// FIXME: Make the 42 not hardcoded // FIXME: Make the 42 not hardcoded
if vote_count < 42 || week != sqlx::query_scalar("SELECT number from Weeks WHERE number == $1 AND is_last_week == 1;") if vote_count < 42 || week == sqlx::query_scalar("SELECT number from Weeks WHERE is_last_week == 1;")
.bind(week)
.fetch_optional(&mut **db) .fetch_optional(&mut **db)
.await.unwrap_or(Some(0)).unwrap_or(0) { .await.unwrap_or(Some(0)).unwrap_or(0) {
return None; return None;