---
# System prepended metadata

title: Untitled

---



```ruby
# app/services/goocus_api/authorizable_factory.rb から
module GoocusAPI::AuthorizableFactory
  class << self
    def load_authorization_of! authorizable
      product = Product.find_by! code: Product::FreshersProduct::CODE
      ProductAuthorization.find_or_initialize_by product: product, authorizable: authorizable
    end
  end
end


# TODO: (1)対象のgoocus_company、goocus_groupを未連携に戻す
# TODO: (2)User,Adminを再連携する → 関連するgoocus_company等も再連携される (例: GoocusAPI::Authorizable::Create)
# →ID順に処理すれば上記の対応は必要なし

ApiCommunicationLog.where(comunication_destination: 'fresher_api').
  where("created_at >= ?", DateTime.new(2020, 4, 5, 20, 0, 0)).order(:id).where.not(id: [1194500, 1195698]).each do |api_log|
    case api_log.loggable_type
    when "User"
      if api_log.entry_point == "create_user"
        authorization = GoocusAPI::AuthorizableFactory.load_authorization_of! api_log.loggable
        authorization.update! product_user_code: nil unless authorization.new_record?
      elsif api_log.entry_point == "edit_user"
        # 何もしない
      end
    when "GoocusCompany"
      if api_log.entry_point == "create_company"
        goocus_company_id = api_log.loggable_id
        GoocusCompany.find(goocus_company_id).update!(goocus_company_code: nil)
      end
    when "GoocusGroup"
      if api_log.entry_point == "create_course_flows"
        goocus_group_id = api_log.loggable_id
        GoocusGroup.find(goocus_group_id).update!(course_flows_api_sent: false)
      elsif api_log.entry_point == "create_group"
        goocus_group_id = api_log.loggable_id
        GoocusGroup.find(goocus_group_id).update!(goocus_group_code: nil)
      end
    when "Admin"
      if api_log.entry_point == "create_admin"
        authorization = GoocusAPI::AuthorizableFactory.load_authorization_of! api_log.loggable
        authorization.update! product_user_code: nil unless authorization.new_record?
      elsif api_log.entry_point == "edit_admin"
        # 何もしない
      end
    end
    GoocusAPI::Factory.build!(api_log.loggable).perform!
    puts "api log id: #{api_log.id} is finished"
end
```

## 備考
- user,adminに関してはapplied_personnels, applied_students, applied_student_programsにも連携フラグあり？


```ruby
 .limit(1)
 .where.not(id: [1194500, 1195698])
```

```ruby
# app/services/goocus_api/authorizable/create.rb から
def company_param
    # companyがAPI未連携なら連携する
    {company: authorizable.goocus_groups.api_associated.take&.goocus_company&.load_goocus_company_code}
  end
end
```