Environment variable option for minimum teacher vote selection count #95

Merged
dergrimm merged 2 commits from minimum-teacher-selection-amount into main 2022-03-13 11:03:20 +00:00
4 changed files with 6 additions and 1 deletions
Showing only changes of commit 3938486cd2 - Show all commits

View file

@ -22,6 +22,7 @@ POSTGRES_USER="mw"
POSTGRES_PASSWORD=
# Backend
BACKEND_MIN_TEACHER_SELECTION_COUNT=
BACKEND_URL=URL
# Backend - API
BACKEND_API_GRAPHQL_PLAYGROUND=false

View file

@ -77,6 +77,7 @@ services:
- redis
environment:
BACKEND_URL: ${URL}
BACKEND_MIN_TEACHER_SELECTION_COUNT: ${BACKEND_MIN_TEACHER_SELECTION_COUNT}
BACKEND_API_GRAPHQL_PLAYGROUND: ${BACKEND_API_GRAPHQL_PLAYGROUND}
BACKEND_API_JWT_SECRET: ${BACKEND_API_JWT_SECRET}
BACKEND_API_JWT_EXPIRATION: ${BACKEND_API_JWT_EXPIRATION}

View file

@ -143,7 +143,7 @@ module Backend
def create_vote(context : Context, input : VoteCreateInput) : Vote
context.student!
raise "Not enough teachers" if input.teacher_ids.empty?
raise "Not enough teachers" if input.teacher_ids.size < Backend.config.min_teacher_selection_count
teacher_role_count = Db::User.where(role: Db::UserRole::Teacher.to_s).count.run.as(Int64)
raise "Teachers not registered" if teacher_role_count != Db::Teacher.count ||
teacher_role_count.zero?

View file

@ -58,6 +58,9 @@ module Backend
# Base URL of application
getter url : String
# Minimum teacher selection count
getter min_teacher_selection_count : Int32
@[EnvConfig::Setting(key: "api")]
# Configuration for `Api`
getter api : ApiConfig