Wrap timestamp filter params in the filter attribute [SCI-8738-updated]

This commit is contained in:
wandji20 2023-08-09 08:25:01 +01:00
parent ab758c747f
commit 02115cf967

View file

@ -246,12 +246,16 @@ module Api
end
def timestamps_filter(records)
from = params.dig(:created_at, :from).present? ? Date.parse(params.dig(:created_at, :from)) : nil
to = params.dig(:created_at, :to).present? ? Date.parse(params.dig(:created_at, :to)) : nil
from = Date.parse(params.dig(:filter, :created_at, :from)) if
params.dig(:filter, :created_at, :from).present?
to = Date.parse(params.dig(:filter, :created_at, :to)) if
params.dig(:filter, :created_at, :to).present?
records = records.where(created_at: (from..to)) if from || to
from = params.dig(:updated_at, :from).present? ? Date.parse(params.dig(:updated_at, :from)) : nil
to = params.dig(:updated_at, :to).present? ? Date.parse(params.dig(:updated_at, :to)) : nil
from = Date.parse(params.dig(:filter, :updated_at, :from)) if
params.dig(:filter, :updated_at, :from).present?
to = Date.parse(params.dig(:filter, :updated_at, :to)) if
params.dig(:filter, :updated_at, :to).present?
records = records.where(updated_at: (from..to)) if from || to
records