2022-07-16 23:28:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Timelogs
|
|
|
|
class BaseService
|
|
|
|
include BaseServiceUtility
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
attr_accessor :current_user
|
2022-07-16 23:28:13 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
def initialize(user)
|
2022-07-16 23:28:13 +05:30
|
|
|
@current_user = user
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
def success(timelog)
|
|
|
|
ServiceResponse.success(payload: {
|
|
|
|
timelog: timelog
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def error(message, http_status = nil)
|
|
|
|
ServiceResponse.error(message: message, http_status: http_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_in_save(timelog)
|
2023-03-04 22:38:38 +05:30
|
|
|
return error(_("Failed to save timelog"), 404) if timelog.errors.empty?
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
error(timelog.errors.full_messages.to_sentence, 404)
|
2022-08-27 11:52:29 +05:30
|
|
|
end
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
|
|
|
end
|