diff --git a/app/api/mobile/apis/project_packages.rb b/app/api/mobile/apis/project_packages.rb index 591e54b1..e619ce74 100644 --- a/app/api/mobile/apis/project_packages.rb +++ b/app/api/mobile/apis/project_packages.rb @@ -112,7 +112,7 @@ module Mobile package = current_user.project_packages.new ::ProjectPackages::SaveService.new(package, symbolize_params).call package.increment_visit_count! - render_ok + render_ok(id: package.id) rescue ::ProjectPackages::SaveService::Error => ex render_error(ex.message) end @@ -142,7 +142,7 @@ module Mobile ::ProjectPackages::SaveService.new(package, symbolize_params).call package.increment_visit_count! - render_ok + render_ok(id: package.id) rescue ::ProjectPackages::SaveService::Error => ex render_error(ex.message) end diff --git a/app/api/mobile/entities/project_package.rb b/app/api/mobile/entities/project_package.rb index de0e7218..85f8bb14 100644 --- a/app/api/mobile/entities/project_package.rb +++ b/app/api/mobile/entities/project_package.rb @@ -20,14 +20,6 @@ module Mobile package.published_at.try(:utc).try(:iso8601) end - expose :can_bidding, if: { type: :show } do |package, opts| - package.can_bidding?(opts[:user]) - end - - expose :can_select_bidding_user, if: { type: :show } do |package, opts| - opts[:user].id == package.creator_id && !package.bidding_end? - end - expose :creator, if: { type: :show } do |package, _| { id: package.creator.id, @@ -60,6 +52,19 @@ module Mobile } end end + + expose :operation, if: { type: :show } do |package, opts| + user = opts[:user] + is_creator = user.id == package.creator_id + is_admin = user.admin? || user.business? + + { + can_bidding: package.can_bidding?(user), + can_select_bidding_user: package.bidding_end? && package.end_bidding? && (is_creator || is_admin), + can_edit: package.editable? && (is_creator || is_admin), + can_delete: package.deletable? && (is_creator || is_admin) + } + end end end end diff --git a/app/models/project_package.rb b/app/models/project_package.rb index 08d2c612..f957dc5d 100644 --- a/app/models/project_package.rb +++ b/app/models/project_package.rb @@ -68,9 +68,13 @@ class ProjectPackage < ActiveRecord::Base pending? || refused? end + def deadline? + deadline_at < Time.now + end + def bidding_end? - flag = deadline_at < Time.now - end_bidding! if flag && can_end_bidding? + flag = deadline? + end_bidding! if flag && may_end_bidding? flag end