Class: Wiq::Commands::CheckIns

Inherits:
Base
  • Object
show all
Defined in:
lib/wiq/commands/check_ins.rb

Constant Summary collapse

STATUS_TO_INT =

Match CheckIn.statuses in app/models/check_in.rb (integer-backed Rails enum). Ransack 4.x does not translate enum strings on integer columns, so the CLI translates here. Without this, q silently drops and returns all check-ins regardless of status.

{
  "unknown" => 0,
  "present" => 1,
  "absent" => 2,
  "excused" => 3,
  "unexcused" => 4,
  "late" => 5,
  "injured" => 6,
  "other" => 7
}.freeze
STATUSES =
STATUS_TO_INT.keys.freeze

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Instance Method Details

#event(event_id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wiq/commands/check_ins.rb', line 34

def event(event_id)
  params = { "per_page" => 50 }
  params["q[status_eq]"] = STATUS_TO_INT.fetch(options[:status]) if options[:status]
  records, total = fetch_index("/api/v1/events/#{event_id}/check_ins", params, key: "check_ins")
  render_index(
    records, total: total,
    summary: "Listed #{records.size} check-ins for event #{event_id}.",
    breadcrumbs: [
      { "cmd" => "wiq events show #{event_id}", "description" => "See the event itself" }
    ]
  )
end

#summaryObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/wiq/commands/check_ins.rb', line 94

def summary
  report_type = options[:feed] ? "CheckInFeedReport" : "CheckInSummaryReport"
  args = {}
  args["roster_id"] = options[:roster] if options[:roster]

  body = {
    report: {
      type: report_type,
      version: "v1",
      name: "CLI #{report_type} #{options[:start]}..#{options[:end]}",
      start_at: options[:start],
      end_at: options[:end],
      args: args
    }
  }

  report = client.post("/api/v1/reports", body)
  if options[:wait]
    report = Reports.poll(client, report["id"], timeout: options[:timeout])
  end

  render(report,
         summary: "#{report_type} ##{report["id"]} status=#{report["status"]}.",
         breadcrumbs: [
           { "cmd" => "wiq reports show #{report["id"]}", "description" => "Refetch later" },
           { "cmd" => "wiq reports types", "description" => "See other recommended report types" }
         ])
end

#wrestler(wrestler_id) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wiq/commands/check_ins.rb', line 57

def wrestler(wrestler_id)
  params = { "per_page" => 50 }
  params["q[created_at_gteq]"] = options[:since] if options[:since]
  records, total = fetch_index("/api/v1/wrestlers/#{wrestler_id}/check_ins", params, key: "check_ins")
  render_index(
    records, total: total,
    summary: "Listed #{records.size} check-ins for wrestler #{wrestler_id}.",
    breadcrumbs: [
      { "cmd" => "wiq wrestlers show #{wrestler_id}",
        "description" => "See the wrestler's profile" },
      { "cmd" => "wiq reports run LastPracticeAttendedReport --roster <id>",
        "description" => "Find ghost wrestlers across a roster" }
    ]
  )
end