@ -29,17 +29,6 @@ type ApiResult<T> =
* Get club profile
* /
export async function getClubProfile ( clubId : number ) : Promise < ApiResult < ClubProfile > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 300 ) ) ;
const mockProfile = getMockClubProfile ( clubId ) ;
return { success : true , data : mockProfile } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } ` , {
method : 'GET' ,
@ -80,42 +69,6 @@ export async function updateClubProfile(
clubId : number ,
request : ClubProfileUpdateRequest
) : Promise < ApiResult < ClubProfile > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 500 ) ) ;
// Simple validation
if ( ! request . name || request . name . trim ( ) . length === 0 ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Validation Error' ,
status : 400 ,
detail : 'One or more fields failed validation' ,
code : 'validation_error' ,
errors : [
{
field : 'name' ,
message : 'Name is required' ,
} ,
] ,
} ,
} ;
}
const mockProfile : ClubProfile = {
. . . getMockClubProfile ( clubId ) ,
. . . request ,
updated_at : new Date ( ) . toISOString ( ) ,
} ;
return { success : true , data : mockProfile } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } ` , {
method : 'PATCH' ,
@ -151,17 +104,6 @@ export async function updateClubProfile(
* Get courts for a club
* /
export async function getCourts ( clubId : number ) : Promise < ApiResult < Court [ ] > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 300 ) ) ;
const mockCourts = getMockCourts ( clubId ) ;
return { success : true , data : mockCourts } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /courts ` , {
method : 'GET' ,
@ -199,61 +141,6 @@ export async function createCourt(
clubId : number ,
request : CourtRequest
) : Promise < ApiResult < Court > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 500 ) ) ;
// Simple validation
if ( ! request . name || request . name . trim ( ) . length === 0 ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Validation Error' ,
status : 400 ,
detail : 'Court name is required' ,
code : 'validation_error' ,
errors : [
{
field : 'name' ,
message : 'Court name is required' ,
} ,
] ,
} ,
} ;
}
// Check for duplicate name (in mock data)
const existingCourts = getMockCourts ( clubId ) ;
if ( existingCourts . some ( c = > c . name . toLowerCase ( ) === request . name . trim ( ) . toLowerCase ( ) ) ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Duplicate Court Name' ,
status : 409 ,
detail : ` A court with the name ' ${ request . name } ' already exists for this club ` ,
code : 'court_name_duplicate' ,
} ,
} ;
}
const newCourt : Court = {
court_id : Math.max ( . . . existingCourts . map ( c = > c . court_id ) , 100 ) + 1 ,
name : request.name.trim ( ) ,
created_at : new Date ( ) . toISOString ( ) ,
updated_at : new Date ( ) . toISOString ( ) ,
} ;
// Add to mock data (in-memory only)
mockCourtsData . push ( newCourt ) ;
return { success : true , data : newCourt } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /courts ` , {
method : 'POST' ,
@ -293,77 +180,6 @@ export async function updateCourt(
courtId : number ,
request : CourtRequest
) : Promise < ApiResult < Court > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 500 ) ) ;
// Simple validation
if ( ! request . name || request . name . trim ( ) . length === 0 ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Validation Error' ,
status : 400 ,
detail : 'Court name is required' ,
code : 'validation_error' ,
errors : [
{
field : 'name' ,
message : 'Court name is required' ,
} ,
] ,
} ,
} ;
}
// Check for duplicate name (excluding current court)
const existingCourts = getMockCourts ( clubId ) ;
if ( existingCourts . some ( c = > c . court_id !== courtId && c . name . toLowerCase ( ) === request . name . trim ( ) . toLowerCase ( ) ) ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Duplicate Court Name' ,
status : 409 ,
detail : ` A court with the name ' ${ request . name } ' already exists for this club ` ,
code : 'court_name_duplicate' ,
} ,
} ;
}
const court = existingCourts . find ( c = > c . court_id === courtId ) ;
if ( ! court ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Court Not Found' ,
status : 404 ,
detail : 'Court not found' ,
code : 'court_not_found' ,
} ,
} ;
}
const updatedCourt : Court = {
. . . court ,
name : request.name.trim ( ) ,
updated_at : new Date ( ) . toISOString ( ) ,
} ;
// Update in mock data (in-memory only)
const index = mockCourtsData . findIndex ( c = > c . court_id === courtId ) ;
if ( index !== - 1 ) {
mockCourtsData [ index ] = updatedCourt ;
}
return { success : true , data : updatedCourt } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /courts/ ${ courtId } ` , {
method : 'PATCH' ,
@ -402,35 +218,6 @@ export async function getCourtDependencies(
clubId : number ,
courtId : number
) : Promise < ApiResult < CourtDependencies > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 300 ) ) ;
// Mock dependencies - first court has dependencies, others don't
const mockDeps : CourtDependencies = courtId === 101 ? {
court_id : courtId ,
can_delete : false ,
dependencies : {
slot_definitions : 12 ,
slot_instances_future : 34 ,
slot_instances_booked : 11 ,
} ,
} : {
court_id : courtId ,
can_delete : true ,
dependencies : {
slot_definitions : 0 ,
slot_instances_future : 0 ,
slot_instances_booked : 0 ,
} ,
} ;
return { success : true , data : mockDeps } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /courts/ ${ courtId } /dependencies ` , {
method : 'GET' ,
@ -468,38 +255,6 @@ export async function deleteCourt(
clubId : number ,
courtId : number
) : Promise < ApiResult < void > > {
// Use mock data for now (until backend is ready)
const USE_MOCKS = false ;
if ( USE_MOCKS ) {
// Simulate API delay
await new Promise ( resolve = > setTimeout ( resolve , 500 ) ) ;
// Check dependencies first
const depsResult = await getCourtDependencies ( clubId , courtId ) ;
if ( depsResult . success && ! depsResult . data . can_delete ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Court Has Dependencies' ,
status : 409 ,
detail : 'Cannot delete court because it is referenced by slot definitions or upcoming bookings' ,
code : 'court_has_dependencies' ,
dependencies : depsResult.data.dependencies ,
} ,
} ;
}
// Remove from mock data (in-memory only)
const index = mockCourtsData . findIndex ( c = > c . court_id === courtId ) ;
if ( index !== - 1 ) {
mockCourtsData . splice ( index , 1 ) ;
}
return { success : true , data : undefined } ;
}
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /courts/ ${ courtId } ` , {
method : 'DELETE' ,