vendredi 30 octobre 2020

How to add a default value to sort: in query_type.rb

Existing code in query_type.rb:

def flags(program_id:, filter: {}, sort: {})
      program = Program.find(program_id)
      context[:auth].set_current_parent_program_id(program.id)
      flags = Report.joins(:participant).where(registrants: { program_id: program.id })
      Types::Programs::FlagsFilter.get_filtered(flags: flags, filter: filter, sort: sort)
 end

I am new to Ruby and the flags are coming in reverse order (ascending) and I want to set the default value to descending. I tried setting it like this:

def flags(program_id:, filter: {}, sort: { column: 'CREATED_AT', direction: 'DESCENDING' })
      program = Program.find(program_id)
      context[:auth].set_current_parent_program_id(program.id)
      flags = Report.joins(:participant).where(registrants: { program_id: program.id })
      Types::Programs::FlagsFilter.get_filtered(flags: flags, filter: filter, sort: sort)
 end

but I'm getting an error and my flags table is no longer rendering. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire