dev_cs
parent
f1ff06df79
commit
e535c92410
@ -0,0 +1,20 @@
|
||||
class CreateSubjectCourseStudentJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(course_id)
|
||||
course = Course.find_by(id: course_id)
|
||||
return if course.blank? || course.subject.blank?
|
||||
|
||||
attrs = %i[course_id user_id role created_at updated_at]
|
||||
same_attrs = {course_id: course.id, role: 4}
|
||||
|
||||
CourseMember.bulk_insert(*attrs) do |worker|
|
||||
course.subject.subject_appointments.each do |app|
|
||||
next if course.students.where(user_id: user_id).any?
|
||||
worker.add same_attrs.merge(user_id: app.user_id)
|
||||
end
|
||||
end
|
||||
|
||||
course.subject.subject_appointments.destroy_all
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateSubjectCourseStudentJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue