Added non existent teacher validation to vote
This commit is contained in:
parent
2cdbe4ec82
commit
011ea15eef
|
@ -111,6 +111,10 @@ module MW
|
|||
def create_vote(context : Context, input : VoteCreateInput) : Vote
|
||||
context.role! UserRole::Student
|
||||
|
||||
if input.teacher_ids.any? { |id| Db::Teacher.find(id).nil? }
|
||||
raise "Teachers not found"
|
||||
end
|
||||
|
||||
student = context.external.not_nil!.as(Db::Student)
|
||||
vote = Db::Vote.create!(student_id: student.id)
|
||||
Db::TeacherVote.import(input.teacher_ids.map_with_index { |id, i| Db::TeacherVote.new(vote_id: vote.id, teacher_id: id.to_i64, priority: i) })
|
||||
|
|
Loading…
Reference in a new issue