Class: Api::V1::WorkEffortAssociationsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::WorkEffortAssociationsController
- Defined in:
- app/controllers/api/v1/work_effort_associations_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/api/v1/work_effort_associations_controller.rb', line 25 def create begin ActiveRecord::Base.connection.transaction do work_effort_association = WorkEffortAssociation.new work_effort_association.work_effort_id_from = params[:work_effort_id_from] work_effort_association.work_effort_id_to = params[:work_effort_id_to] work_effort_association.work_effort_association_type = WorkEffortAssociationType.where('external_identifier = ?', params['work_effort_association_type.external_identifier'].to_s).first work_effort_association.save! render :json => {success: true, work_effort_association: work_effort_association.to_data_hash} end rescue ActiveRecord::RecordInvalid => invalid Rails.logger.error invalid.record.errors render :json => {:success => false, :message => invalid.record.errors} rescue StandardError => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier render json: {success: false, message: 'Error creating Work Effort Association'} end end |
#destroy ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/api/v1/work_effort_associations_controller.rb', line 81 def destroy work_effort_association = WorkEffortAssociation.find(params[:id]) begin ActiveRecord::Base.connection.transaction do render json: {success: work_effort_association.destroy} end rescue StandardError => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier render json: {success: false, message: 'Error destroying Work Effort Association'} end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/api/v1/work_effort_associations_controller.rb', line 5 def index work_effort_associations = WorkEffortAssociation if params[:project_id] work_effort_associations = work_effort_associations.joins('inner join work_efforts on work_efforts.id = work_effort_associations.work_effort_id_to') .where('work_efforts.project_id = ?', params[:project_id]) else # scope by dba organization work_effort_associations = work_effort_associations.joins('inner join work_efforts on work_efforts.id = work_effort_associations.work_effort_id_to') .joins("inner join entity_party_roles on entity_party_roles.entity_record_type = 'WorkEffort' and entity_party_roles.entity_record_id = work_efforts.id") .where('entity_party_roles.party_id = ? and entity_party_roles.role_type_id = ?', current_user.party.dba_organization.id, RoleType.iid('dba_org').id) end render :json => {success: true, work_effort_associations: work_effort_associations.all.map { |work_effort| work_effort.to_data_hash }} end |
#show ⇒ Object
21 22 23 |
# File 'app/controllers/api/v1/work_effort_associations_controller.rb', line 21 def show render :json => {success: true, work_effort_association: WorkEffortAssociation.find(params[:id]).to_data_hash} end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/api/v1/work_effort_associations_controller.rb', line 53 def update begin ActiveRecord::Base.connection.transaction do work_effort_association = WorkEffortAssociation.find(params[:id]) work_effort_association.work_effort_id_from = params[:work_effort_id_from] work_effort_association.work_effort_id_to = params[:work_effort_id_to] work_effort_association.work_effort_association_type = WorkEffortAssociationType.where('external_identifier = ?', params[:work_effort_association_type_external_id].to_s).first work_effort_association.save! render :json => {success: true, work_effort_association: work_effort_association.to_data_hash} end rescue ActiveRecord::RecordInvalid => invalid Rails.logger.error invalid.record.errors render :json => {:success => false, :message => invalid.record.errors} rescue StandardError => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier render json: {success: false, message: 'Error updating Work Effort Association'} end end |