Fix password report
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
b9b311dc1c
commit
4b9d5ffe60
|
@ -11,6 +11,7 @@ module Backend::Api::Loaders
|
|||
getter user_teacher = UserTeacher.new
|
||||
|
||||
getter student = Student.new
|
||||
getter student_vote = StudentVote.new
|
||||
|
||||
getter teacher = Teacher.new
|
||||
|
||||
|
|
|
@ -5,4 +5,16 @@ module Backend::Api::Loaders
|
|||
ids.map { |id| students.find { |u| u.id == id } }
|
||||
end
|
||||
end
|
||||
|
||||
class StudentVote < GraphQL::DataLoader::Loader(Backend::Db::Student, Int32, Backend::Db::Vote?)
|
||||
def key_for(student : Db::Student)
|
||||
student.id
|
||||
end
|
||||
|
||||
def fetch(batch students : Array(Db::Student)) : Array(Db::Vote?)
|
||||
student_ids = students.map(&.id)
|
||||
votes = Db::Vote.query.where { student_id.in?(student_ids) }.to_a
|
||||
student_ids.map { |s| votes.find { |v| v.student_id == s } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Backend::Api::Loaders
|
|||
def fetch(batch users : Array(Db::User)) : Array(Db::Student?)
|
||||
user_ids = users.map(&.id)
|
||||
students = Db::Student.query.where { user_id.in?(user_ids) }.to_a
|
||||
users.map { |u| students.find { |s| s.user_id == u.id } }
|
||||
user_ids.map { |u| students.find { |s| s.user_id == u } }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,7 +26,7 @@ module Backend::Api::Loaders
|
|||
def fetch(batch users : Array(Db::User)) : Array(Db::Teacher?)
|
||||
user_ids = users.map(&.id)
|
||||
teachers = Db::Teacher.query.where { user_id.in?(user_ids) }.to_a
|
||||
users.map { |u| teachers.find { |t| t.user_id == u.id } }
|
||||
user_ids.map { |u| teachers.find { |t| t.user_id == u } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -91,16 +91,16 @@ module Backend
|
|||
# User.new(user)
|
||||
# end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Deletes user by ID
|
||||
def delete_user(context : Context, id : Int32) : Int32?
|
||||
context.admin!
|
||||
# @[GraphQL::Field]
|
||||
# # Deletes user by ID
|
||||
# def delete_user(context : Context, id : Int32) : Int32?
|
||||
# context.admin!
|
||||
|
||||
user = Db::User.find!(id)
|
||||
user.delete
|
||||
# user = Db::User.find!(id)
|
||||
# user.delete
|
||||
|
||||
id
|
||||
end
|
||||
# id
|
||||
# end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Starts assignment job of mentors to students
|
||||
|
@ -212,6 +212,8 @@ module Backend
|
|||
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, priority: i}) })
|
||||
|
||||
context.loaders.vote.prime(vote.id, vote)
|
||||
|
||||
Vote.new(vote)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
require "./scalars/*"
|
||||
|
||||
module Backend::Api::Schema::Scalars
|
||||
end
|
||||
|
|
|
@ -26,14 +26,16 @@ module Backend
|
|||
|
||||
@[GraphQL::Field]
|
||||
# Student's user
|
||||
def user : User
|
||||
User.new(@model.user)
|
||||
def user(context : Context) : User
|
||||
# User.new(@model.user)
|
||||
User.new(context.loaders.user.load(@model.user_id.to_i32).not_nil!)
|
||||
end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Student's vote
|
||||
def vote : Vote?
|
||||
@model.vote.try { |v| Vote.new(v) }
|
||||
def vote(context : Context) : Vote?
|
||||
# @model.vote.try { |v| Vote.new(v) }
|
||||
context.loaders.student_vote.load(@model).try { |v| Vote.new(v) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -38,8 +38,10 @@ module Backend
|
|||
|
||||
@[GraphQL::Field]
|
||||
# Students' votes
|
||||
def teacher_votes : Array(TeacherVote)
|
||||
Db::TeacherVote.query.where { teacher_id == @model.id }.map { |tv| TeacherVote.new(tv) }
|
||||
def teacher_votes(context : Context) : Array(TeacherVote)
|
||||
context.loaders.teacher_vote
|
||||
.load(Db::TeacherVote.query.select(:id).where { teacher_id == @model.id }.map(&.id))
|
||||
.map { |tv| TeacherVote.new(tv.not_nil!) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -38,8 +38,9 @@ module Backend
|
|||
|
||||
@[GraphQL::Field]
|
||||
# Student's vote
|
||||
def vote : Vote
|
||||
Vote.new(@model.vote)
|
||||
def vote(context : Context) : Vote
|
||||
# Vote.new(@model.vote)
|
||||
Vote.new(context.loaders.vote.load(@model.vote_id.to_i32).not_nil!)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,14 +26,18 @@ module Backend
|
|||
|
||||
@[GraphQL::Field]
|
||||
# Student who voted
|
||||
def student : Student
|
||||
Student.new(@model.student)
|
||||
def student(context : Context) : Student
|
||||
# Student.new(@model.student)
|
||||
Student.new(context.loaders.student.load(@model.student.id).not_nil!)
|
||||
end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Teacher votes for student
|
||||
def teacher_votes : Array(TeacherVote)
|
||||
@model.teacher_votes.map { |tv| TeacherVote.new(tv) }
|
||||
def teacher_votes(context : Context) : Array(TeacherVote)
|
||||
# @model.teacher_votes.map { |tv| TeacherVote.new(tv) }
|
||||
context.loaders.teacher_vote
|
||||
.load(@model.teacher_votes.select(:id).map(&.id))
|
||||
.map { |tv| TeacherVote.new(tv.not_nil!) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -185,7 +185,11 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code><%= teacher.password %></code>
|
||||
<%- if teacher.password -%>
|
||||
<code><%= teacher.password %></code>
|
||||
<%- else -%>
|
||||
<i>Password geändert</i>
|
||||
<%- end -%>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
query Users {
|
||||
users {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
username
|
||||
role
|
||||
admin
|
||||
}
|
||||
}
|
|
@ -4,4 +4,5 @@ pub mod ok;
|
|||
pub mod students_can_vote;
|
||||
pub mod teachers;
|
||||
pub mod tokens;
|
||||
pub mod users;
|
||||
pub mod users_by_role;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
use graphql_client::GraphQLQuery;
|
||||
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.graphql",
|
||||
query_path = "graphql/queries/users.graphql",
|
||||
response_derives = "Debug",
|
||||
skip_serializing_none
|
||||
)]
|
||||
pub struct Users;
|
Loading…
Reference in New Issue