2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module TimeFrameArguments
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
OVERLAPPING_TIMEFRAME_DESC = 'List items overlapping a time frame defined by startDate..endDate (if one date is provided, both must be present)'
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
included do
|
|
|
|
argument :start_date, Types::TimeType,
|
|
|
|
required: false,
|
2021-01-03 14:25:43 +05:30
|
|
|
description: OVERLAPPING_TIMEFRAME_DESC,
|
|
|
|
deprecated: { reason: 'Use timeframe.start', milestone: '13.5' }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
argument :end_date, Types::TimeType,
|
|
|
|
required: false,
|
2021-01-03 14:25:43 +05:30
|
|
|
description: OVERLAPPING_TIMEFRAME_DESC,
|
|
|
|
deprecated: { reason: 'Use timeframe.end', milestone: '13.5' }
|
|
|
|
|
|
|
|
argument :timeframe, Types::TimeframeInputType,
|
|
|
|
required: false,
|
|
|
|
description: 'List items overlapping the given timeframe'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
# TODO: remove when the start_date and end_date arguments are removed
|
2020-03-13 15:44:24 +05:30
|
|
|
def validate_timeframe_params!(args)
|
2021-01-03 14:25:43 +05:30
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
error_message =
|
2021-01-03 14:25:43 +05:30
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
"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
|
|
|
|
end
|