fix: add missing scope and config_snapshot fields to createCompetition

Backend requires scope and config_snapshot when creating competition
without a template. Frontend now:
- Defaults scope to 'facility' when facility_id is provided
- Renames config to config_snapshot for backend compatibility
- Provides empty config_snapshot when no template_id
master
Guillermo Pages 1 week ago
parent 2a71371683
commit b91f2d47bc

@ -263,10 +263,26 @@ export async function createCompetition(
request: CreateCompetitionRequest
): Promise<CompetitionApiResult<Competition>> {
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', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ...request, facility_id: facilityId }),
body: JSON.stringify(body),
});
const result = await handleApiResponse<{ competition: Competition }>(response);

Loading…
Cancel
Save