vote: Always display graph for the admin
This commit is contained in:
parent
c4e252dbc2
commit
0c162d3b42
3 changed files with 6 additions and 5 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -578,7 +578,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fabula_votes_server"
|
name = "fabula_votes_server"
|
||||||
version = "1.2.1"
|
version = "1.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"blake2",
|
"blake2",
|
||||||
|
|
|
@ -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.1"
|
version = "1.3.0"
|
||||||
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
|
||||||
|
|
|
@ -96,7 +96,8 @@ pub struct VoteData {
|
||||||
|
|
||||||
// TODO: Cache vote count ? Maintain in state ?
|
// TODO: Cache vote count ? Maintain in state ?
|
||||||
#[get("/<week>/votes", format = "application/json")]
|
#[get("/<week>/votes", format = "application/json")]
|
||||||
pub async fn fetch_vote_data(week: u8, mut db: Connection<database::Db>) -> Option<Json<VoteData>> {
|
pub async fn fetch_vote_data(week: u8, mut db: Connection<database::Db>, cookies: &CookieJar<'_>) -> Option<Json<VoteData>> {
|
||||||
|
let user = auth::get_user(week, &mut db, cookies).await;
|
||||||
let raw_votes: Vec<VotingData> = sqlx::query_as("
|
let raw_votes: Vec<VotingData> = sqlx::query_as("
|
||||||
SELECT Players.name as votes_for, Truths.number as truth_number, count(*) as votes FROM Votes
|
SELECT Players.name as votes_for, Truths.number as truth_number, count(*) as votes FROM Votes
|
||||||
JOIN Players ON Votes.voted_id == Players.id
|
JOIN Players ON Votes.voted_id == Players.id
|
||||||
|
@ -124,11 +125,11 @@ 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.
|
||||||
if max_vote_count == 0
|
if !user.is_admin && (max_vote_count == 0
|
||||||
|| vote_count < max_vote_count
|
|| vote_count < max_vote_count
|
||||||
|| week == sqlx::query_scalar("SELECT number from Weeks WHERE is_last_week == 1;")
|
|| week == sqlx::query_scalar("SELECT number from Weeks WHERE is_last_week == 1;")
|
||||||
.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue