Skip to content

Commit 065f726

Browse files
committed
Add team location creation endpoint
1 parent 5adbb76 commit 065f726

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
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

0 commit comments

Comments
 (0)