@@ -118,16 +118,18 @@ function parseProgramSchedule(formData: FormData): ParseResult<ProgramSchedule>
118118 } ;
119119}
120120
121- function parseCoachId ( formData : FormData ) : ParseResult < string > {
122- const raw = field ( formData , "coach_id " ) ;
121+ function parseCoordinatorId ( formData : FormData ) : ParseResult < string > {
122+ const raw = field ( formData , "coordinator_id " ) ;
123123 if ( ! raw )
124124 return {
125125 ok : false ,
126- errors : { coach_id : [ "A coach is required for private lessons" ] } ,
126+ errors : {
127+ coordinator_id : [ "A coordinator is required for private lessons" ] ,
128+ } ,
127129 } ;
128130 const result = z . string ( ) . uuid ( ) . safeParse ( raw ) ;
129131 if ( ! result . success ) {
130- return { ok : false , errors : { coach_id : [ "Invalid coach " ] } } ;
132+ return { ok : false , errors : { coordinator_id : [ "Invalid coordinator " ] } } ;
131133 }
132134 return { ok : true , value : result . data } ;
133135}
@@ -156,7 +158,7 @@ export async function createService(
156158 }
157159
158160 // Validate price format independently so its error reports alongside
159- // schedule/coach errors instead of in a separate round-trip.
161+ // schedule/coordinator errors instead of in a separate round-trip.
160162 const priceRaw = formData . get ( "price_cad" ) ?. toString ( ) ?? "" ;
161163 let cents : number | null = null ;
162164 if ( priceRaw && ! errors . price_cad ) {
@@ -166,11 +168,11 @@ export async function createService(
166168 }
167169 }
168170
169- // Schedule / coach checks key off the submitted type, not parsed.data,
171+ // Schedule / coordinator checks key off the submitted type, not parsed.data,
170172 // so they still run when baseFields fails on unrelated fields.
171173 const typeRaw = formData . get ( "type" ) ?. toString ( ) ;
172174 let scheduledAtValue : ProgramSchedule | null = null ;
173- let coachIdValue : string | null = null ;
175+ let coordinatorIdValue : string | null = null ;
174176 if ( typeRaw === "programs" ) {
175177 const result = parseProgramSchedule ( formData ) ;
176178 if ( ! result . ok ) {
@@ -179,9 +181,9 @@ export async function createService(
179181 scheduledAtValue = result . value ;
180182 }
181183 } else if ( typeRaw === "private_lessons" ) {
182- const coach = parseCoachId ( formData ) ;
183- if ( ! coach . ok ) Object . assign ( errors , coach . errors ) ;
184- else coachIdValue = coach . value ;
184+ const coordinator = parseCoordinatorId ( formData ) ;
185+ if ( ! coordinator . ok ) Object . assign ( errors , coordinator . errors ) ;
186+ else coordinatorIdValue = coordinator . value ;
185187 }
186188
187189 if ( Object . keys ( errors ) . length > 0 ) {
@@ -210,7 +212,7 @@ export async function createService(
210212 slots : scheduledAtValue ?. slots ?? null ,
211213 durationMinutes : duration_minutes ,
212214 stripeProductId : productId ,
213- coachId : coachIdValue ,
215+ coordinatorId : coordinatorIdValue ,
214216 status : "active" ,
215217 } ) ;
216218 } catch ( e ) {
@@ -306,20 +308,23 @@ export async function updateService(
306308 }
307309
308310 let scheduledAtValue : ProgramSchedule | undefined ;
309- let coachIdValue : string | undefined ;
311+ let coordinatorIdValue : string | undefined ;
310312 if ( row . type === "programs" && formData . has ( "start_date" ) ) {
311313 const result = parseProgramSchedule ( formData ) ;
312314 if ( ! result . ok ) {
313315 Object . assign ( errors , result . errors ) ;
314316 } else {
315317 scheduledAtValue = result . value ;
316318 }
317- } else if ( row . type === "private_lessons" && formData . has ( "coach_id" ) ) {
318- // Private lessons can be reassigned to a different coach, but the coach
319- // remains mandatory: an empty/invalid value is rejected.
320- const coach = parseCoachId ( formData ) ;
321- if ( ! coach . ok ) Object . assign ( errors , coach . errors ) ;
322- else coachIdValue = coach . value ;
319+ } else if (
320+ row . type === "private_lessons" &&
321+ formData . has ( "coordinator_id" )
322+ ) {
323+ // Private lessons can be reassigned to a different coordinator, but the
324+ // coordinator remains mandatory: an empty/invalid value is rejected.
325+ const coordinator = parseCoordinatorId ( formData ) ;
326+ if ( ! coordinator . ok ) Object . assign ( errors , coordinator . errors ) ;
327+ else coordinatorIdValue = coordinator . value ;
323328 }
324329
325330 if ( Object . keys ( errors ) . length > 0 ) {
@@ -350,13 +355,13 @@ export async function updateService(
350355
351356 const dbPatch : Partial < typeof services . $inferInsert > = { } ;
352357 if ( duration_minutes !== undefined ) dbPatch . durationMinutes = duration_minutes ;
353- if ( coachIdValue !== undefined ) dbPatch . coachId = coachIdValue ;
358+ if ( coordinatorIdValue !== undefined )
359+ dbPatch . coordinatorId = coordinatorIdValue ;
354360 if ( scheduledAtValue !== undefined ) {
355361 dbPatch . startDate = scheduledAtValue . startDate ;
356362 dbPatch . endDate = scheduledAtValue . endDate ;
357363 dbPatch . slots = scheduledAtValue . slots ;
358364 }
359- if ( coachIdValue !== undefined ) dbPatch . coachId = coachIdValue ;
360365
361366 if ( Object . keys ( dbPatch ) . length > 0 ) {
362367 dbPatch . updatedAt = new Date ( ) ;
0 commit comments