change create function for issue controller, add invocation of blockchain related function and add ActiveRecord Rollback operation
This commit is contained in:
parent
f230c0d640
commit
fcc17eb07b
|
@ -105,44 +105,55 @@ class IssuesController < ApplicationController
|
||||||
elsif params[:subject].to_s.size > 255
|
elsif params[:subject].to_s.size > 255
|
||||||
normal_status(-1, "标题不能超过255个字符")
|
normal_status(-1, "标题不能超过255个字符")
|
||||||
else
|
else
|
||||||
issue_params = issue_send_params(params)
|
ActiveRecord::Base.transaction do
|
||||||
|
issue_params = issue_send_params(params)
|
||||||
|
|
||||||
@issue = Issue.new(issue_params)
|
@issue = Issue.new(issue_params)
|
||||||
if @issue.save!
|
if @issue.save!
|
||||||
if params[:attachment_ids].present?
|
if params[:attachment_ids].present?
|
||||||
params[:attachment_ids].each do |id|
|
params[:attachment_ids].each do |id|
|
||||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||||
unless attachment.blank?
|
unless attachment.blank?
|
||||||
attachment.container = @issue
|
attachment.container = @issue
|
||||||
attachment.author_id = current_user.id
|
attachment.author_id = current_user.id
|
||||||
attachment.description = ""
|
attachment.description = ""
|
||||||
attachment.save
|
attachment.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if params[:issue_tag_ids].present?
|
||||||
if params[:issue_tag_ids].present?
|
params[:issue_tag_ids].each do |tag|
|
||||||
params[:issue_tag_ids].each do |tag|
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
end
|
||||||
|
end
|
||||||
|
if params[:assigned_to_id].present?
|
||||||
|
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||||
|
container_id: @issue.id, container_type: 'Issue',
|
||||||
|
parent_container_id: @project.id, parent_container_type: "Project",
|
||||||
|
tiding_type: 'issue', status: 0)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if params[:assigned_to_id].present?
|
|
||||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
|
||||||
container_id: @issue.id, container_type: 'Issue',
|
|
||||||
parent_container_id: @project.id, parent_container_type: "Project",
|
|
||||||
tiding_type: 'issue', status: 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
#为悬赏任务时, 扣除当前用户的积分
|
#为悬赏任务时, 扣除当前用户的积分
|
||||||
if params[:issue_type].to_s == "2"
|
if params[:issue_type].to_s == "2"
|
||||||
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
|
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
|
||||||
end
|
end
|
||||||
|
|
||||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
render json: {status: 0, message: "创建成", id: @issue.id}
|
|
||||||
else
|
# author: zxh
|
||||||
normal_status(-1, "创建失败")
|
# 调用上链API
|
||||||
|
success_blockchain = push_activity_2_blockchain("issue_create", @issue)
|
||||||
|
if success_blockchain == false
|
||||||
|
normal_status(-1, "创建失败")
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
else
|
||||||
|
render json: {status: 0, message: "创建成", id: @issue.id}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
normal_status(-1, "创建失败")
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue