Skip to content

Commit 00ccbf5

Browse files
committed
feat: implement ticket validation
1 parent 1e11bdc commit 00ccbf5

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/modules/support/controllers/staff_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def calculate_dashboard_stats
8989
total_tickets: SupportTicket.count,
9090
open: SupportTicket.where(status: 'open').count,
9191
in_progress: SupportTicket.where(status: 'in_progress').count,
92-
waiting_client: SupportTicket.where(status: 'waiting_client').count,
92+
waiting_user: SupportTicket.where(status: 'waiting_user').count,
9393
resolved_today: SupportTicket.where('resolved_at >= ?', Time.current.beginning_of_day).count,
9494
unassigned: SupportTicket.unassigned.open_tickets.count,
9595
my_tickets: SupportTicket.where(assigned_to: current_user).open_tickets.count,

app/modules/support/controllers/tickets_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def create
4848
ticket.organization = current_organization
4949

5050
# Run chatbot if description provided
51+
chatbot_result = nil
5152
if ticket.description.present?
5253
chatbot_result = ChatbotService.new(ticket).generate_suggestions
5354
ticket.chatbot_attempted = true
@@ -58,7 +59,10 @@ def create
5859
# Send notification
5960
Support::TicketNotificationJob.perform_later(ticket.id, 'created')
6061

61-
render_created({ ticket: serialize_ticket_detail(ticket) })
62+
render_created({
63+
ticket: serialize_ticket_detail(ticket),
64+
chatbot_response: chatbot_result
65+
})
6266
else
6367
render_error(message: ticket.errors.full_messages.join(', '), status: :unprocessable_entity)
6468
end

app/modules/support/models/support_ticket.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ class SupportTicket < ApplicationRecord
3535
validates :subject, presence: true, length: { minimum: 5, maximum: 200 }
3636
validates :description, presence: true, length: { minimum: 10 }
3737
validates :category, presence: true, inclusion: {
38-
in: %w[technical feature_request billing riot_integration other]
38+
in: %w[technical feature_request billing riot_integration getting_started other]
3939
}
4040
validates :priority, presence: true, inclusion: {
4141
in: %w[low medium high urgent]
4242
}
4343
validates :status, presence: true, inclusion: {
44-
in: %w[open in_progress waiting_client resolved closed]
44+
in: %w[open in_progress waiting_user resolved closed]
4545
}
4646

4747
# Scopes
48-
scope :open_tickets, -> { where(status: %w[open in_progress waiting_client]) }
48+
scope :open_tickets, -> { where(status: %w[open in_progress waiting_user]) }
4949
scope :closed_tickets, -> { where(status: %w[resolved closed]) }
5050
scope :unassigned, -> { where(assigned_to_id: nil) }
5151
scope :assigned, -> { where.not(assigned_to_id: nil) }
@@ -60,7 +60,8 @@ class SupportTicket < ApplicationRecord
6060

6161
# Instance methods
6262
def ticket_number
63-
"TICKET-#{id&.split('-')&.first&.upcase || 'DRAFT'}"
63+
prefix = id ? id.split('-').first.upcase : 'DRAFT'
64+
"TICKET-#{prefix}"
6465
end
6566

6667
def assign_to!(user)
@@ -131,8 +132,9 @@ def track_status_changes
131132
end
132133

133134
def create_system_message(content)
135+
system_actor = assigned_to || user
134136
messages.create!(
135-
user: User.system_user, # You'll need to create a system user
137+
user: system_actor,
136138
content: content,
137139
message_type: 'system'
138140
)

0 commit comments

Comments
 (0)