From 79c73ee57ac89f04a1f7a5e2b1eb03d9da8589ce Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Sat, 15 Jan 2022 19:06:32 +0100 Subject: [PATCH] Fixed create vote mutation --- docker/backend/src/mw/schema/mutation.cr | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/docker/backend/src/mw/schema/mutation.cr b/docker/backend/src/mw/schema/mutation.cr index 9d606a5..141973c 100644 --- a/docker/backend/src/mw/schema/mutation.cr +++ b/docker/backend/src/mw/schema/mutation.cr @@ -109,25 +109,11 @@ module MW @[GraphQL::Field] def create_vote(context : Context, input : VoteCreateInput) : Vote - # context.admin! - - # student = Db::Student.find!(input.student_id) - # # student.vote = Db::Vote.new(student_id: student.id) - # # student.save! - # pp! Db::Vote.create!(student_id: student.id.not_nil!) - # pp! student - # pp! student.vote - # input.teacher_ids.not_nil!.each_with_index do |t_id, i| - # Db::TeacherVote.create!(vote_id: student.vote.not_nil!.id.not_nil!, teacher_id: t_id, priority: i) - # end if input.teacher_ids - # pp! student.vote.not_nil!.teacher_votes.to_a - - # Vote.new(student.vote.not_nil!) - context.role! UserRole::Student 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) }) Vote.new(vote) end