Return hashes from user ban use cases

This commit is contained in:
Karina Kwiatek 2022-07-23 15:33:35 +02:00
parent a8e99723cc
commit 050d7d5b56
2 changed files with 22 additions and 14 deletions

View file

@ -1,13 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'use_case/base' require "use_case/base"
module UseCase module UseCase
module User module User
class Ban < UseCase::Base class Ban < UseCase::Base
REASON_SPAM = 'Spam' REASON_SPAM = "Spam"
REASON_HARASSMENT = 'Harassment' REASON_HARASSMENT = "Harassment"
REASON_BAN_EVASION = 'Ban evasion' REASON_BAN_EVASION = "Ban evasion"
option :target_user_id, type: Types::Coercible::Integer option :target_user_id, type: Types::Coercible::Integer
option :expiry, types: Types::Nominal::DateTime.optional option :expiry, types: Types::Nominal::DateTime.optional
@ -20,18 +20,22 @@ module UseCase
if reason == REASON_SPAM if reason == REASON_SPAM
target_user.update!( target_user.update!(
profile_picture: nil, profile_picture: nil,
profile_header: nil profile_header: nil
) )
target_user.profile.update!( target_user.profile.update!(
display_name: nil, display_name: nil,
description: '', description: "",
location: '', location: "",
website: '', website: ""
) )
end end
{ {
ban: ban status: 201,
resource: ban,
extra: {
target_user:
}
} }
end end
@ -40,11 +44,7 @@ module UseCase
end end
def source_user def source_user
if source_user_id @source_user ||= ::User.find(source_user_id) if source_user_id
@source_user ||= ::User.find(source_user_id)
else
nil
end
end end
end end
end end

View file

@ -9,6 +9,14 @@ module UseCase
def call def call
target_user.unban target_user.unban
{
status: 204,
resource: nil,
extra: {
target_user: target_user
}
}
end end
def target_user def target_user