Merge pull request #559 from Retrospring/return-hashes-from-use-cases
This commit is contained in:
commit
d9a2e7dde8
|
@ -32,8 +32,11 @@ module UseCase
|
|||
inbox = ::Inbox.create!(user: target_user, question: question, new: true)
|
||||
|
||||
{
|
||||
question: question,
|
||||
inbox: inbox
|
||||
status: 201,
|
||||
resource: question,
|
||||
extra: {
|
||||
inbox:
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ module UseCase
|
|||
QuestionWorker.perform_async(source_user_id, question.id)
|
||||
|
||||
{
|
||||
question: question
|
||||
status: 201,
|
||||
resource: question
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ module UseCase
|
|||
raise Errors::Forbidden unless current_user&.mod? || question.user == current_user
|
||||
|
||||
question.destroy!
|
||||
|
||||
{
|
||||
status: 204,
|
||||
resource: nil,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'use_case/base'
|
||||
require "use_case/base"
|
||||
|
||||
module UseCase
|
||||
module User
|
||||
class Ban < UseCase::Base
|
||||
REASON_SPAM = 'Spam'
|
||||
REASON_HARASSMENT = 'Harassment'
|
||||
REASON_BAN_EVASION = 'Ban evasion'
|
||||
REASON_SPAM = "Spam"
|
||||
REASON_HARASSMENT = "Harassment"
|
||||
REASON_BAN_EVASION = "Ban evasion"
|
||||
|
||||
option :target_user_id, type: Types::Coercible::Integer
|
||||
option :expiry, types: Types::Nominal::DateTime.optional
|
||||
|
@ -20,18 +20,22 @@ module UseCase
|
|||
if reason == REASON_SPAM
|
||||
target_user.update!(
|
||||
profile_picture: nil,
|
||||
profile_header: nil
|
||||
profile_header: nil
|
||||
)
|
||||
target_user.profile.update!(
|
||||
display_name: nil,
|
||||
description: '',
|
||||
location: '',
|
||||
website: '',
|
||||
description: "",
|
||||
location: "",
|
||||
website: ""
|
||||
)
|
||||
end
|
||||
|
||||
{
|
||||
ban: ban
|
||||
status: 201,
|
||||
resource: ban,
|
||||
extra: {
|
||||
target_user:
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -40,11 +44,7 @@ module UseCase
|
|||
end
|
||||
|
||||
def source_user
|
||||
if source_user_id
|
||||
@source_user ||= ::User.find(source_user_id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
@source_user ||= ::User.find(source_user_id) if source_user_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,14 @@ module UseCase
|
|||
|
||||
def call
|
||||
target_user.unban
|
||||
|
||||
{
|
||||
status: 204,
|
||||
resource: nil,
|
||||
extra: {
|
||||
target_user: target_user
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def target_user
|
||||
|
|
|
@ -19,11 +19,11 @@ describe UseCase::Question::CreateFollowers do
|
|||
let(:author_identifier) { nil }
|
||||
|
||||
it "creates question" do
|
||||
expect(subject[:question]).to be_persisted
|
||||
expect(subject[:resource]).to be_persisted
|
||||
end
|
||||
|
||||
it "enqueues a QuestionWorker job" do
|
||||
expect(QuestionWorker).to have_enqueued_sidekiq_job(source_user.id, subject[:question].id)
|
||||
expect(QuestionWorker).to have_enqueued_sidekiq_job(source_user.id, subject[:resource].id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue