From c88e2df19c5111b72791922986e302fe75d9f410 Mon Sep 17 00:00:00 2001 From: Soufiane Date: Tue, 21 Feb 2023 14:36:24 +0100 Subject: [PATCH] Fix filter_date action when only one date is present [SCI-7942] (#5005) Fix filter_date action when only one date is present [SCI-7942] --- .../activity_filter_matching_service.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/services/activities/activity_filter_matching_service.rb b/app/services/activities/activity_filter_matching_service.rb index 1fc373bfc..93eba70e8 100644 --- a/app/services/activities/activity_filter_matching_service.rb +++ b/app/services/activities/activity_filter_matching_service.rb @@ -26,9 +26,18 @@ module Activities def filter_date! @activity_filters = @activity_filters.where( - "((filter ->> 'from_date') = '' AND (filter ->> 'to_date') = '') OR " \ - "((?)::date BETWEEN (filter ->> 'from_date')::date AND (filter ->> 'to_date')::date)", - @activity.created_at.to_date + "(CASE "\ + "WHEN (filter ->> 'to_date') = '' " \ + "THEN :date >= '-infinity'::date " \ + "ELSE :date >= (filter ->> 'to_date')::date " \ + "END) " \ + " AND " \ + "(CASE "\ + "WHEN (filter ->> 'from_date') = '' " \ + "THEN :date <= 'infinity'::date " \ + "ELSE :date <= (filter ->> 'from_date')::date "\ + "END)", + date: @activity.created_at.to_date ) end