File tree Expand file tree Collapse file tree
app/controllers/api/testing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class API ::Testing ::TeamLocationsController < API ::Testing ::BaseController
4+ def create
5+ organisation = Organisation . find_by! ( ods_code : params [ :workgroup ] )
6+ school = Location . school . find ( params [ :school_id ] )
7+ academic_year = AcademicYear . pending
8+
9+ team_locations =
10+ organisation . teams . map do |team |
11+ TeamLocation . find_or_create_by! (
12+ team :,
13+ location : school ,
14+ academic_year :
15+ )
16+ end
17+
18+ render json : team_locations , status : :created
19+ rescue ActiveRecord ::RecordInvalid => e
20+ render json : { errors : e . record . errors } , status : :unprocessable_entity
21+ rescue ActiveRecord ::RecordNotFound => e
22+ render json : { error : e . message } , status : :not_found
23+ end
24+ end
Original file line number Diff line number Diff line change 113113 namespace :testing do
114114 post "onboard" , to : "onboard#create"
115115 post "patients" , to : "patients#create"
116+ post "team-locations" , to : "team_locations#create"
116117
117118 resources :locations , only : :index
118119 resources :teams , only : :destroy , param : :workgroup do
You can’t perform that action at this time.
0 commit comments