Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Mailing
- class OnboardingTeacherService
- include Service
- handle_asynchronously :call, queue: 'mailing'
- def initialize(operation, options = {})
- @operation = operation
- @options = options
- end
- def call
- send(@operation, @options) if respond_to?(@operation, true)
- end
- private
- def send_teacher_how_to_add_students(options)
- return unless options[:teacher]
- return unless Feature.teacher_how_to_add_students?
- teacher = options[:teacher]
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher.groups.any? && teacher.students.uniq.count < 2
- AzbookaMailer.send_mail(:teacher_how_to_add_students, teacher_how_to_add_students_params(teacher))
- end
- def teacher_how_to_add_students_params(teacher)
- class_book = teacher.class_books.first
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name
- }
- end
- def send_help_for_teacher_with_add_students(options)
- return unless options[:teacher]
- return unless Feature.help_for_teacher_with_add_students?
- teacher = options[:teacher]
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
- return unless teacher.groups.any? && teacher.students.uniq.count < 3
- AzbookaMailer.send_mail(:help_for_teacher_with_add_students, help_for_teacher_with_add_students_params(teacher))
- end
- def help_for_teacher_with_add_students_params(teacher)
- class_book = teacher.class_books.order(created_at: :desc).first
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name,
- classid: class_book.id
- }
- end
- def send_teacher_how_to_add_parents(options)
- return unless options[:teacher]
- return unless Feature.teacher_how_to_add_parents?
- teacher = options[:teacher]
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher.groups.present? && teacher.students.present? &&
- teacher.students.all? { |s| s.parent2_id.nil? }
- AzbookaMailer.send_mail(:teacher_how_to_add_parents, teacher_how_to_add_parent_params(teacher))
- end
- def teacher_how_to_add_parent_params(teacher)
- {
- email: teacher.email,
- tname: teacher.io,
- classid: teacher.group_with_most_students_without_parents.id
- }
- end
- def send_help_for_teacher_to_add_parents(options)
- return unless options[:teacher]
- return unless Feature.help_for_teacher_to_add_parents?
- teacher = options[:teacher]
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
- return unless teacher.groups.any? && teacher.students.uniq.count >= 3 && teacher.students.none?(&:parent2_id)
- AzbookaMailer.send_mail(:help_for_teacher_to_add_parents, help_for_teacher_to_add_parents_params(teacher))
- end
- def help_for_teacher_to_add_parents_params(teacher)
- class_book = teacher.group_with_most_students_without_parents.class_book
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name,
- students: class_book.students.map(&:name_with_short_surname).join(', '),
- classid: class_book
- }
- end
- def send_activation_certificate_for_teacher_activity(options)
- return unless options[:teacher]
- return unless Feature.activation_certificate_for_teacher_activity?
- teacher = options[:teacher]
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher&.class_books&.any? && (teacher.students.count == 5) &&
- teacher.students.all? { |s| s.parent2.present? }
- AzbookaMailer.send_mail(:activation_certificate_for_teacher_activity,
- activation_certificate_for_teacher_activity_params(teacher))
- end
- def activation_certificate_for_teacher_activity_params(teacher)
- {
- email: teacher.email,
- tname: teacher.io
- }
- end
- def send_teacher_activation_certificate_for_add_parents(options)
- return unless options[:class_book]
- return unless Feature.teacher_activation_certificate_for_add_parents?
- class_book = options[:class_book]
- return if class_book.teacher.email.blank?
- return unless class_book.teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return if class_book.students.count < 5 && class_book.students.any? { |student| student.parent2.present? }
- AzbookaMailer.send_mail(:teacher_activation_certificate_for_add_parents,
- teacher_activation_certificate_for_add_parents_params(class_book))
- end
- def teacher_activation_certificate_for_add_parents_params(class_book)
- {
- email: class_book.teacher.email,
- tname: class_book.teacher.io,
- addedclass: class_book.name,
- addedclassID: class_book.id,
- APnumber: class_book.students.count,
- APChild1: class_book.students[0].name_with_short_surname,
- APChild2: class_book.students[1].name_with_short_surname,
- APChild3: class_book.students[2].name_with_short_surname,
- APChild4: class_book.students[3].name_with_short_surname,
- APChild5: class_book.students[4].name_with_short_surname
- }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement