Rename filter_timestamps_range to timestamp_filters [SCI-8738]

This commit is contained in:
wandji20 2023-07-31 11:21:40 +01:00
parent 8e96c2427a
commit 1e64a246fe
38 changed files with 93 additions and 95 deletions

View file

@ -48,26 +48,5 @@ module Api
end
render json: response, status: :ok
end
private
def filter_timestamp_range(records)
from = params.dig(:create_date_start)
to = params.dig(:create_date_end)
column = 'created_at'
if from.blank? || to.blank?
from = params.dig(:update_date_start)
to = params.dig(:update_date_end)
column = 'updated_at'
end
return records if from.blank? || to.blank?
if column == 'created_at'
records.where(created_at: (from..to))
else
records.where(updated_at: (from..to))
end
end
end
end

View file

@ -9,7 +9,7 @@ module Api
def index
attachments =
filter_timestamp_range(@step.assets).page(params.dig(:page, :number))
timestamps_filter(@step.assets).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: attachments, each_serializer: AssetSerializer

View file

@ -244,6 +244,25 @@ module Api
raise FilterParamError
end
end
def timestamps_filter(records)
from = params.dig(:created_at, :from)
to = params.dig(:created_at, :to)
return records.where(created_at: (from..to)) if
valid_date?(*from&.split('-')&.map(&:to_i)) && valid_date?(*to&.split('-')&.map(&:to_i))
from = params.dig(:updated_at, :from)
to = params.dig(:updated_at, :to)
return records.where(updated_at: (from..to)) if
valid_date?(*from&.split('-')&.map(&:to_i)) && valid_date?(*to&.split('-')&.map(&:to_i))
records
end
def valid_date?(year = '', month = '', day = '')
Date.new(year, month, day) rescue false
end
end
end
end

View file

@ -13,7 +13,7 @@ module Api
def index
checklist_items =
filter_timestamp_range(@checklist.checklist_items).page(params.dig(:page, :number))
timestamps_filter(@checklist.checklist_items).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: checklist_items, each_serializer: ChecklistItemSerializer

View file

@ -11,7 +11,7 @@ module Api
def index
checklists =
filter_timestamp_range(@step.checklists).page(params.dig(:page, :number))
timestamps_filter(@step.checklists).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: checklists, each_serializer: ChecklistSerializer, include: include_params

View file

@ -12,7 +12,7 @@ module Api
def index
user_assignments =
filter_timestamp_range(@experiment.user_assignments).includes(:user_role)
timestamps_filter(@experiment.user_assignments).includes(:user_role)
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -11,7 +11,7 @@ module Api
before_action :load_experiment_for_managing, only: %i(update)
def index
experiments = filter_timestamp_range(@project.experiments)
experiments = timestamps_filter(@project.experiments)
experiments = archived_filter(experiments).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: experiments, each_serializer: ExperimentSerializer

View file

@ -12,7 +12,7 @@ module Api
def index
inventories =
filter_timestamp_range(@team.repositories).active
timestamps_filter(@team.repositories).active
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -12,7 +12,7 @@ module Api
def index
cells =
filter_timestamp_range(
timestamps_filter(
@inventory_item.repository_cells
)
.preload(:repository_column, value: @inventory.cell_preload_includes)

View file

@ -12,7 +12,7 @@ module Api
def index
checklist_items =
filter_timestamp_range(@inventory_column.repository_checklist_items).page(params.dig(:page, :number))
timestamps_filter(@inventory_column.repository_checklist_items).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: checklist_items, each_serializer: InventoryChecklistItemSerializer

View file

@ -12,7 +12,7 @@ module Api
before_action :check_create_permissions, only: %i(create)
def index
columns = filter_timestamp_range(@inventory.repository_columns).includes(:repository_list_items)
columns = timestamps_filter(@inventory.repository_columns).includes(:repository_list_items)
.includes(:repository_status_items)
.includes(:repository_checklist_items)
.includes(:repository_stock_unit_items)

View file

@ -13,7 +13,7 @@ module Api
def index
items =
filter_timestamp_range(
timestamps_filter(
@inventory.repository_rows
)
.active

View file

@ -11,7 +11,7 @@ module Api
before_action :check_manage_permissions, only: %i(create update destroy)
def index
list_items = filter_timestamp_range(@inventory_column.repository_list_items).page(params.dig(:page, :number))
list_items = timestamps_filter(@inventory_column.repository_list_items).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: list_items, each_serializer: InventoryListItemSerializer

View file

@ -9,7 +9,7 @@ module Api
def index
status_items =
filter_timestamp_range(
timestamps_filter(
@inventory_column.repository_status_items
)
.repository_status_items

View file

@ -12,7 +12,7 @@ module Api
def index
stock_unit_items =
filter_timestamp_range(
timestamps_filter(
@inventory_column.repository_stock_unit_items
)
.page(params.dig(:page, :number))

View file

@ -9,7 +9,7 @@ module Api
before_action :load_project_comment, only: :show
def index
project_comments = filter_timestamp_range(@project.project_comments).page(params.dig(:page, :number))
project_comments = timestamps_filter(@project.project_comments).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: project_comments,

View file

@ -7,7 +7,7 @@ module Api
before_action :load_project_folder, only: %i(show update)
def index
project_folders = filter_timestamp_range(@team.project_folders).page(params.dig(:page, :number))
project_folders = timestamps_filter(@team.project_folders).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: project_folders, each_serializer: ProjectFolderSerializer

View file

@ -19,7 +19,7 @@ module Api
end
def index
user_assignments = filter_timestamp_range(@project.user_assignments).includes(:user_role)
user_assignments = timestamps_filter(@project.user_assignments).includes(:user_role)
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -11,7 +11,7 @@ module Api
before_action :load_project_for_managing, only: %i(update)
def index
projects = filter_timestamp_range(@team.projects.visible_to(current_user, @team))
projects = timestamps_filter(@team.projects.visible_to(current_user, @team))
projects = archived_filter(projects).page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -12,7 +12,7 @@ module Api
def index
protocol_templates =
filter_timestamp_range(
timestamps_filter(
Protocol.latest_available_versions(@team)
)
.viewable_by_user(current_user, @team)

View file

@ -11,7 +11,7 @@ module Api
end
def index
protocols = filter_timestamp_range(@task.protocols).page(params.dig(:page, :number))
protocols = timestamps_filter(@task.protocols).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: protocols,
each_serializer: ProtocolSerializer, rte_rendering: render_rte?, team: @team

View file

@ -8,7 +8,7 @@ module Api
before_action :load_report, only: :show
def index
reports = filter_timestamp_range(@project.reports).page(params.dig(:page, :number))
reports = timestamps_filter(@project.reports).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: reports,
each_serializer: ReportSerializer,

View file

@ -8,7 +8,7 @@ module Api
before_action :check_manage_permissions, only: %i(create update)
def index
results = filter_timestamp_range(@task.results).page(params.dig(:page, :number))
results = timestamps_filter(@task.results).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: results, each_serializer: ResultSerializer,
include: (%i(text table file) << include_params).flatten.compact

View file

@ -10,7 +10,7 @@ module Api
before_action :load_step_text_for_managing, only: %i(update destroy)
def index
step_texts = filter_timestamp_range(@step.step_texts).page(params.dig(:page, :number))
step_texts = timestamps_filter(@step.step_texts).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: step_texts, each_serializer: StepTextSerializer, include: include_params

View file

@ -13,7 +13,7 @@ module Api
before_action :check_delete_permissions, only: :destroy
def index
steps = filter_timestamp_range(@protocol.steps).page(params.dig(:page, :number))
steps = timestamps_filter(@protocol.steps).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: steps, each_serializer: StepSerializer,

View file

@ -10,7 +10,7 @@ module Api
before_action :load_table_for_managing, only: %i(update destroy)
def index
tables = filter_timestamp_range(@step.tables).page(params.dig(:page, :number))
tables = timestamps_filter(@step.tables).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: tables, each_serializer: TableSerializer

View file

@ -10,7 +10,7 @@ module Api
before_action :check_manage_permissions, only: %i(create destroy)
def index
users = filter_timestamp_range(User).joins(:user_my_modules)
users = timestamps_filter(User).joins(:user_my_modules)
.where(user_my_modules: { my_module_id: @task.id })
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -9,7 +9,7 @@ module Api
before_action :load_task_group, only: :show
def index
task_groups = filter_timestamp_range(@experiment.my_module_groups).page(params.dig(:page, :number))
task_groups = timestamps_filter(@experiment.my_module_groups).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: task_groups, each_serializer: TaskGroupSerializer, include: include_params
end

View file

@ -12,7 +12,7 @@ module Api
def index
items =
filter_timestamp_range(@task.repository_rows).includes(repository_cells: :repository_column)
timestamps_filter(@task.repository_rows).includes(repository_cells: :repository_column)
.preload(repository_cells: :value)
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -10,7 +10,7 @@ module Api
before_action :load_tag, only: :show
def index
tags = filter_timestamp_range(@task.tags).page(params.dig(:page, :number))
tags = timestamps_filter(@task.tags).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: tags, each_serializer: TagSerializer
end

View file

@ -12,7 +12,7 @@ module Api
before_action :load_user_assignment_for_managing, only: %i(update show)
def index
user_assignments = filter_timestamp_range(@task.user_assignments).includes(:user_role)
user_assignments = timestamps_filter(@task.user_assignments).includes(:user_role)
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))

View file

@ -10,7 +10,7 @@ module Api
before_action :load_user, only: :show
def index
users = filter_timestamp_range(@task.users).page(params.dig(:page, :number))
users = timestamps_filter(@task.users).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: users, each_serializer: UserSerializer
end

View file

@ -16,7 +16,7 @@ module Api
def index
tasks =
filter_timestamp_range(
timestamps_filter(
@experiment.my_modules
).includes(:my_module_status, :my_modules, :my_module_antecessors)
tasks = archived_filter(tasks).page(params.dig(:page, :number))

View file

@ -8,7 +8,7 @@ module Api
end
def index
teams = filter_timestamp_range(current_user.teams).page(params.dig(:page, :number))
teams = timestamps_filter(current_user.teams).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: teams, each_serializer: TeamSerializer
end

View file

@ -7,7 +7,7 @@ module Api
before_action :load_user_identity, only: %i(show update destroy)
def index
identities = filter_timestamp_range(@user.user_identities).page(params.dig(:page, :number))
identities = timestamps_filter(@user.user_identities).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: identities, each_serializer: UserIdentitySerializer
end

View file

@ -7,7 +7,7 @@ module Api
before_action :load_user, only: :show
def index
users = filter_timestamp_range(@team.users).page(params.dig(:page, :number))
users = timestamps_filter(@team.users).page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: users, each_serializer: UserSerializer
end

View file

@ -6,7 +6,7 @@ module Api
before_action :load_workflow
def index
statuses = filter_timestamp_range(@workflow.my_module_statuses)
statuses = timestamps_filter(@workflow.my_module_statuses)
render jsonapi: statuses, each_serializer: WorkflowStatusSerializer
end
end

View file

@ -8,7 +8,7 @@ module Api
end
def index
workflows = filter_timestamp_range(MyModuleStatusFlow.all)
workflows = timestamps_filter(MyModuleStatusFlow.all)
render jsonapi: workflows, each_serializer: WorkflowSerializer
end