class Sorting::GuideProgress::ByMessages
Public Class Methods
add_progress_count()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 22 def self.add_progress_count { 'progresses.unread': '$count' } end
filter_guide_assignments()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 50 def self.filter_guide_assignments { 'assignments': { '$filter': { 'as': 'assignment', 'input': '$assignments', 'cond': { '$eq': %w($$assignment.guide.slug $guide.slug), } } } } end
filter_unread_notifications()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 80 def self.filter_unread_notifications { 'notifications': { '$filter': { 'as': 'notification', 'input': '$notifications', 'cond': { '$and': [ {'$eq': %w($$notification.organization $organization)}, {'$eq': %w($$notification.sender $student.uid)}, {'$eq': %w($$notification.course $course)}, {'$eq': ['$$notification.read', false]} ] } } } } end
generate_guide_progress()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 28 def self.generate_guide_progress { 'progresses': {'$arrayElemAt': ['$progresses', 0]}, } end
group_by_students_uid()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 34 def self.group_by_students_uid { '_id': '$student.uid', 'progresses': {'$push': '$$ROOT'}, 'count': { '$sum': { '$cond': { 'if': {'$anyElementTrue': ['$assignments']}, 'then': 1, 'else': 0 } } } } end
lookup_assignments()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 64 def self.lookup_assignments { 'from': 'assignments', 'localField': 'notifications.assignment_id', 'foreignField': '_id', 'as': 'assignments' } end
lookup_notifications()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 99 def self.lookup_notifications { 'from': 'notifications', 'localField': 'organization', 'foreignField': 'organization', 'as': 'notifications' } end
order_by(ordering)
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 108 def self.order_by(ordering) {'unread': ordering, 'student.last_name': ordering, 'student.first_name': ordering} end
pipeline()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 4 def self.pipeline [ {'$lookup': lookup_notifications}, {'$addFields': filter_unread_notifications}, {'$unwind': unwind_notifications}, {'$lookup': lookup_assignments}, {'$addFields': filter_guide_assignments}, {'$group': group_by_students_uid}, {'$addFields': generate_guide_progress}, {'$addFields': add_progress_count}, {'$replaceRoot': progress_to_document_root}, ] end
progress_to_document_root()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 18 def self.progress_to_document_root {'newRoot': '$progresses'} end
unwind_notifications()
click to toggle source
# File lib/mumuki/classroom/models/sorting/guide_progress.rb, line 73 def self.unwind_notifications { 'path': '$notifications', 'preserveNullAndEmptyArrays': true } end