@ -263,10 +263,26 @@ export async function createCompetition(
request : CreateCompetitionRequest
request : CreateCompetitionRequest
) : Promise < CompetitionApiResult < Competition > > {
) : Promise < CompetitionApiResult < Competition > > {
try {
try {
// Build request body with proper field names for backend
const { config , . . . rest } = request ;
const body : Record < string , unknown > = {
. . . rest ,
facility_id : facilityId ,
scope : request.scope ? ? 'facility' , // Default to facility scope
} ;
// Backend expects config_snapshot, not config
if ( config ) {
body . config_snapshot = config ;
} else if ( ! request . template_id ) {
// Provide empty config_snapshot when creating without template
body . config_snapshot = { } ;
}
const response = await apiFetch ( '/competitions' , {
const response = await apiFetch ( '/competitions' , {
method : 'POST' ,
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' } ,
headers : { 'Content-Type' : 'application/json' } ,
body : JSON.stringify ( { . . . request , facility_id : facilityId } ) ,
body : JSON.stringify ( body ) ,
} ) ;
} ) ;
const result = await handleApiResponse < { competition : Competition } > ( response ) ;
const result = await handleApiResponse < { competition : Competition } > ( response ) ;