refactor(manager data exports): extract method to generate csv
This commit is contained in:
parent
d5de21fac4
commit
2ff224ec47
3 changed files with 17 additions and 24 deletions
|
@ -42,24 +42,16 @@ module Manager
|
|||
|
||||
def export_last_half_year
|
||||
administrateurs = Administrateur.joins(:user).where(created_at: 6.months.ago..).where.not(users: { email_verified_at: nil })
|
||||
csv = CSV.generate(headers: true) do |csv|
|
||||
csv << ['ID', 'Email', 'Date de création']
|
||||
administrateurs.each do |administrateur|
|
||||
csv << [administrateur.id, administrateur.email, administrateur.created_at]
|
||||
end
|
||||
end
|
||||
|
||||
csv = generate_csv(administrateurs)
|
||||
|
||||
send_data csv, filename: "administrateurs_recents_#{Date.today.strftime('%d-%m-%Y')}.csv"
|
||||
end
|
||||
|
||||
def export_with_publiee_procedure
|
||||
administrateurs = Administrateur.joins(:user).where.not(users: { email_verified_at: nil }).joins(:procedures).where(procedures: { aasm_state: [:publiee] })
|
||||
csv = CSV.generate(headers: true) do |csv|
|
||||
csv << ['ID', 'Email', 'Date de création']
|
||||
administrateurs.each do |administrateur|
|
||||
csv << [administrateur.id, administrateur.email, administrateur.created_at]
|
||||
end
|
||||
end
|
||||
|
||||
csv = generate_csv(administrateurs)
|
||||
|
||||
send_data csv, filename: "administrateurs_actifs_#{Date.today.strftime('%d-%m-%Y')}.csv"
|
||||
end
|
||||
|
|
|
@ -56,5 +56,14 @@ module Manager
|
|||
|
||||
payload[:to_log] = to_log
|
||||
end
|
||||
|
||||
def generate_csv(users)
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << ['ID', 'Email', 'Date de création']
|
||||
users.each do |user|
|
||||
csv << [user.id, user.email, user.created_at]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,24 +25,16 @@ module Manager
|
|||
|
||||
def export_last_half_year
|
||||
instructeurs = Instructeur.joins(:user).where(created_at: 6.months.ago..).where.not(users: { email_verified_at: nil })
|
||||
csv = CSV.generate(headers: true) do |csv|
|
||||
csv << ['ID', 'Email', 'Date de création']
|
||||
instructeurs.each do |instructeur|
|
||||
csv << [instructeur.id, instructeur.email, instructeur.created_at]
|
||||
end
|
||||
end
|
||||
|
||||
csv = generate_csv(instructeurs)
|
||||
|
||||
send_data csv, filename: "instructeurs_recents_#{Date.today.strftime('%d-%m-%Y')}.csv"
|
||||
end
|
||||
|
||||
def export_currently_active
|
||||
instructeurs = Instructeur.joins(:user).where(users: { current_sign_in_at: 6.months.ago.. }).where.not(users: { email_verified_at: nil })
|
||||
csv = CSV.generate(headers: true) do |csv|
|
||||
csv << ['ID', 'Email', 'Date de création']
|
||||
instructeurs.each do |instructeur|
|
||||
csv << [instructeur.id, instructeur.email, instructeur.created_at]
|
||||
end
|
||||
end
|
||||
|
||||
csv = generate_csv(instructeurs)
|
||||
|
||||
send_data csv, filename: "instructeurs_actifs_#{Date.today.strftime('%d-%m-%Y')}.csv"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue