Class: EventFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/event_factory.rb

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Class Method Details

.new_project(project, user) ⇒ Object

Creates an event when a new project is created This used to send a notification using EventfulMailer, but it is no longer required


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/event_factory.rb', line 9

def self.new_project(project, user)
  content = "Project registered by #{user.}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: 'Project registered',
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save
end

.project_approved(project, user) ⇒ Object

Creates an event or emails when a project is approved This used to send a notification using EventfulMailer, but it is no longer required


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/event_factory.rb', line 25

def self.project_approved(project, user)
  content = "Project approved by #{user.}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: 'Project approved',
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save
end

.project_refund_request(project, user, reference) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/event_factory.rb', line 39

def self.project_refund_request(project, user, reference)
  content = "Refund request by #{user.}. Reference #{reference}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: "Refund #{reference}",
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save

  # EventfulMailer.deliver_confirm_event(User.all_administrators_emails, event.eventful, event.message, event.content, "No Milestone")
end

.request_update_note_to_manager(request, user, message) ⇒ Object

creates an event and sends an email when update(s) to a request fail


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/event_factory.rb', line 60

def self.request_update_note_to_manager(request, user, message)
  content = "#{message}\nwhilst an attempt was made to update request #{request.id}\nby user '#{user.}' on #{Time.zone.now}"

  request_event = Event.create(
    eventful_id: request.id,
    eventful_type: 'Request',
    message: 'Request update(s) failed',
    created_by: user.,
    content: content,
    of_interest_to: 'manager'
  )

  recipients = []
  request.initial_project.tap do |project|
    recipients << project.manager.email if project && project.manager
  end

  EventfulMailer.confirm_event(recipients.reject(&:blank?), request_event.eventful, request_event.message,
                               request_event.content, 'No Milestone').deliver_now
end