Class: Mks::Edm::EquipmentCategoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mks/edm/equipment_categories_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/mks/edm/equipment_categories_controller.rb', line 32

def create
  @equipment_category = EquipmentCategory.new(equipment_category_params)

  if @equipment_category.save
    response = Mks::Common::MethodResponse.success_response(@equipment_category,
                                'Equipment category created successfully!')
    render json: response, status: :created, location: @equipment_category
  else
    response = Mks::Common::MethodResponse.failure_response(@equipment_category)
    render json: response, status: :unprocessable_entity
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/mks/edm/equipment_categories_controller.rb', line 6

def index
  data = EquipmentCategory.where(equipment_type_id: params[:id])
  render json: Mks::Common::MethodResponse.success_response(data)
end

#nodesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/mks/edm/equipment_categories_controller.rb', line 11

def nodes
  equipment_categories = EquipmentCategory.where(equipment_type_id: params[:id])
  categories = equipment_categories.map do |ec|
    {
      data: {
        id: ec.id,
        code: ec.code,
        name: ec.name,
        description: ec.description,
        type: 'EC'
      },
      leaf: false
    }
  end
  render json: categories
end

#showObject



28
29
30
# File 'app/controllers/mks/edm/equipment_categories_controller.rb', line 28

def show
  render json: Mks::Common::MethodResponse.success_response(@equipment_category)
end

#updateObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/mks/edm/equipment_categories_controller.rb', line 45

def update
  if @equipment_category.update(equipment_category_params)
    response = Mks::Common::MethodResponse.success_response(@equipment_category,
                                'Equipment category updated successfully!')
    render json: response
  else
    response = Mks::Common::MethodResponse.failure_response(@equipment_category)
    render json: response, status: :unprocessable_entity
  end
end