37 lines
1.3 KiB
Ruby
37 lines
1.3 KiB
Ruby
module Suppliers
|
|
class EmployeeShiftsController < Suppliers::ApplicationController
|
|
def index
|
|
@employee_shifts = EmployeeShift.for_supplier(current_supplier, relevant_from: 1.week.ago)
|
|
@employee_shifts.include_relations(:employee, :supplier)
|
|
# Only select shifts from currently linked and employees
|
|
@employee_shifts.select! do |shift|
|
|
current_supplier.employee_ids.include?(shift.employee.try(:id))
|
|
end
|
|
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee supplier])
|
|
end
|
|
def create
|
|
@employee_shift.supplier = current_supplier
|
|
@employee_shift.save
|
|
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee supplier])
|
|
end
|
|
|
|
def update
|
|
@employee_shift.update employee_shift_params
|
|
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer)
|
|
end
|
|
|
|
def destroy
|
|
head :forbidden and return unless @employee_shift.supplier_id == current_supplier.id
|
|
@employee_shift.destroy
|
|
head :ok
|
|
end
|
|
|
|
private
|
|
|
|
def employee_shift_params
|
|
params.require(:employee_shift).permit(:start_from, :end_on, :employee_id, :description)
|
|
end
|
|
|
|
end
|
|
end
|