You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
562 B
12 lines
562 B
module Api
|
|
module V1
|
|
class ReportsController < BaseController
|
|
def monthly
|
|
rows = current_user.entries.group(Arel.sql("DATE_TRUNC('month', date)"), :praktikums_typ, :entry_art)
|
|
.order(Arel.sql("DATE_TRUNC('month', date) DESC"))
|
|
.pluck(Arel.sql("DATE_TRUNC('month', date)"), :praktikums_typ, :entry_art, Arel.sql("SUM(COALESCE(hours, 0) * 60 + COALESCE(minutes, 0))"))
|
|
render json: rows.map { |month, typ, art, minutes| { month: month.to_date, typ:, art:, total_minutes: minutes.to_i } }
|
|
end
|
|
end
|
|
end
|
|
end
|