Class: LesliSupport::CatalogService

Inherits:
Lesli::ApplicationLesliService
  • Object
show all
Defined in:
app/services/lesli_support/catalog_service.rb

Instance Method Summary collapse

Instance Method Details

#create(ticket_params) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/services/lesli_support/catalog_service.rb', line 80

def create(ticket_params)

    ticket = current_user..help.tickets.new(ticket_params)
    #ticket.source = Catalog::TicketSource.cloud_help_source(current_user.account.help)
    ticket.creator = current_user
    ticket.user = current_user

    unless ticket_params.dig(:started_at)
        #ticket.started_at = LC::Date2.new(Time.current).date.get
    end

    if ticket.save
        #Ticket.log_activity_create(current_user, ticket)
        #Ticket::Subscriber.add_subscriber(ticket, current_user, "discussion_created", "email")
        #Workflow::Action.execute_actions(current_user, ticket, {}, ticket.attributes)
        self.resource = ticket
    else
        pp ticket.errors.full_messages
        self.error(ticket.errors.full_messages.to_sentence)
    end

    self
end

#find(ticket_id) ⇒ Object



36
37
38
# File 'app/services/lesli_support/catalog_service.rb', line 36

def find ticket_id
    super(current_user..help.tickets.find_by(id: ticket_id))
end

#indexObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/lesli_support/catalog_service.rb', line 40

def index

    return current_user..support.tickets.left_joins(
        :user, :creator
    ).select(
        :id,
        :subject,
        :deadline,
        :creator_id,
        :user_id,
        "CONCAT_WS(' ', lesli_users.first_name, lesli_users.last_name) as user_name",
        "CONCAT_WS(' ', creators_lesli_support_tickets.first_name, creators_lesli_support_tickets.last_name) as creator_name",
        "lesli_support_tickets.updated_at",
        "lesli_support_tickets.created_at"
    ).order(id: :desc)
    .page(query[:pagination][:page])
    .per(query[:pagination][:perPage])

    current_user..help.tickets.left_joins(
        :priority, 
        :type, 
        :workspace, 
        :category, 
        :status, 
        :assignments,
        :assigned,
        :user
    ).select(
        :id,
        :subject,
        :deadline,
        :assigned_id,
        :user_id,
        "CONCAT_WS(' ', users.first_name, users.last_name) as assigned_name",
        "CONCAT_WS(' ', users_cloud_help_tickets.first_name, users_cloud_help_tickets.last_name) as user_name",
        "cloud_help_tickets.updated_at",
        "cloud_help_tickets.created_at"
    )
end

#optionsObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/services/lesli_support/catalog_service.rb', line 120

def options() 
    catalogs = {}

    # Retrieve all root nodes (nodes with no parent)
    root_catalogs = current_user..support.catalogs
        .where(ancestry: nil)

    # Fetch all trees
    root_catalogs.each do |catalog|
        catalogs[catalog.name.downcase] = {
            id: catalog.id,
            name: catalog.name,
            options: catalog.children
        }
    end

    catalogs
end

#showObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/services/lesli_support/catalog_service.rb', line 104

def show()
    return current_user..help.tickets.left_joins(
        :user, :creator
    ).select(
        :id,
        :subject,
        :deadline,
        :creator_id,
        :user_id,
        "CONCAT_WS(' ', lesli_users.first_name, lesli_users.last_name) as user_name",
        "CONCAT_WS(' ', creators_lesli_support_tickets.first_name, creators_lesli_support_tickets.last_name) as creator_name",
        "lesli_support_tickets.updated_at",
        "lesli_support_tickets.created_at"
    ).where("lesli_support_tickets.id = ?", self.resource.id).first
end