You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/services/admins/create_laboratory_service.rb

20 lines
510 B

class Admins::CreateLaboratoryService < ApplicationService
Error = Class.new(StandardError)
attr_reader :params
def initialize(params)
@params = params
end
def call
raise Error, '单位不能为空' if params[:school_id].blank?
raise Error, '该单位已存在' if Laboratory.exists?(school_id: params[:school_id])
ActiveRecord::Base.transaction do
laboratory = Laboratory.create!(school_id: params[:school_id])
laboratory.create_laboratory_setting!
end
end
end