You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/jobs/create_subject_course_stude...

21 lines
616 B

5 years ago
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|
5 years ago
next if course.students.where(user_id: app.user_id).any?
5 years ago
worker.add same_attrs.merge(user_id: app.user_id)
end
end
course.subject.subject_appointments.destroy_all
end
end