2020-02-05 12:09:15 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module TimeFrameArguments
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2020-10-14 03:08:32 +00:00
|
|
|
OVERLAPPING_TIMEFRAME_DESC = 'List items overlapping a time frame defined by startDate..endDate (if one date is provided, both must be present)'
|
|
|
|
|
2020-02-05 12:09:15 +00:00
|
|
|
included do
|
|
|
|
argument :start_date, Types::TimeType,
|
|
|
|
required: false,
|
2020-10-14 03:08:32 +00:00
|
|
|
description: OVERLAPPING_TIMEFRAME_DESC,
|
2020-10-16 00:08:56 +00:00
|
|
|
deprecated: { reason: 'Use timeframe.start', milestone: '13.5' }
|
2020-02-05 12:09:15 +00:00
|
|
|
|
|
|
|
argument :end_date, Types::TimeType,
|
|
|
|
required: false,
|
2020-10-14 03:08:32 +00:00
|
|
|
description: OVERLAPPING_TIMEFRAME_DESC,
|
2020-10-16 00:08:56 +00:00
|
|
|
deprecated: { reason: 'Use timeframe.end', milestone: '13.5' }
|
2020-10-14 03:08:32 +00:00
|
|
|
|
|
|
|
argument :timeframe, Types::TimeframeInputType,
|
|
|
|
required: false,
|
2021-01-12 00:10:42 +00:00
|
|
|
description: 'List items overlapping the given timeframe.'
|
2020-02-05 12:09:15 +00:00
|
|
|
end
|
|
|
|
|
2020-10-14 03:08:32 +00:00
|
|
|
# TODO: remove when the start_date and end_date arguments are removed
|
2020-02-05 12:09:15 +00:00
|
|
|
def validate_timeframe_params!(args)
|
2020-10-14 03:08:32 +00:00
|
|
|
return unless %i[start_date end_date timeframe].any? { |k| args[k].present? }
|
|
|
|
return if args[:timeframe] && %i[start_date end_date].all? { |k| args[k].nil? }
|
2020-02-05 12:09:15 +00:00
|
|
|
|
|
|
|
error_message =
|
2020-10-14 03:08:32 +00:00
|
|
|
if args[:timeframe].present?
|
|
|
|
"startDate and endDate are deprecated in favor of timeframe. Please use only timeframe."
|
|
|
|
elsif args[:start_date].nil? || args[:end_date].nil?
|
2020-02-05 12:09:15 +00:00
|
|
|
"Both startDate and endDate must be present."
|
|
|
|
elsif args[:start_date] > args[:end_date]
|
|
|
|
"startDate is after endDate"
|
|
|
|
end
|
|
|
|
|
|
|
|
if error_message
|
|
|
|
raise Gitlab::Graphql::Errors::ArgumentError, error_message
|
|
|
|
end
|
|
|
|
end
|
2021-06-09 12:10:27 +00:00
|
|
|
|
|
|
|
def transform_timeframe_parameters(args)
|
|
|
|
if args[:timeframe]
|
|
|
|
args[:timeframe].transform_keys { |k| :"#{k}_date" }
|
|
|
|
else
|
|
|
|
args.slice(:start_date, :end_date)
|
|
|
|
end
|
|
|
|
end
|
2020-02-05 12:09:15 +00:00
|
|
|
end
|