@@ -165,6 +165,7 @@ export async function createService(
165165 // so they still run when baseFields fails on unrelated fields.
166166 const typeRaw = formData . get ( "type" ) ?. toString ( ) ;
167167 let scheduledAtValue : ProgramSchedule | null = null ;
168+ let coachIdValue : string | null = null ;
168169 if ( typeRaw === "programs" ) {
169170 const result = parseProgramSchedule ( formData ) ;
170171 if ( ! result . ok ) {
@@ -175,6 +176,7 @@ export async function createService(
175176 } else if ( typeRaw === "private_lessons" ) {
176177 const coach = parseCoachId ( formData ) ;
177178 if ( ! coach . ok ) Object . assign ( errors , coach . errors ) ;
179+ else coachIdValue = coach . value ;
178180 }
179181
180182 if ( Object . keys ( errors ) . length > 0 ) {
@@ -203,6 +205,7 @@ export async function createService(
203205 slots : scheduledAtValue ?. slots ?? null ,
204206 durationMinutes : duration_minutes ,
205207 stripeProductId : productId ,
208+ coachId : coachIdValue ,
206209 status : "active" ,
207210 } ) ;
208211 } catch ( e ) {
@@ -298,13 +301,18 @@ export async function updateService(
298301 }
299302
300303 let scheduledAtValue : ProgramSchedule | undefined ;
304+ let coachIdValue : string | undefined ;
301305 if ( row . type === "programs" && formData . has ( "start_date" ) ) {
302306 const result = parseProgramSchedule ( formData ) ;
303307 if ( ! result . ok ) {
304308 Object . assign ( errors , result . errors ) ;
305309 } else {
306310 scheduledAtValue = result . value ;
307311 }
312+ } else if ( row . type === "private_lessons" && formData . has ( "coach_id" ) ) {
313+ const coach = parseCoachId ( formData ) ;
314+ if ( ! coach . ok ) Object . assign ( errors , coach . errors ) ;
315+ else coachIdValue = coach . value ;
308316 }
309317
310318 if ( Object . keys ( errors ) . length > 0 ) {
@@ -334,6 +342,7 @@ export async function updateService(
334342 dbPatch . endDate = scheduledAtValue . endDate ;
335343 dbPatch . slots = scheduledAtValue . slots ;
336344 }
345+ if ( coachIdValue !== undefined ) dbPatch . coachId = coachIdValue ;
337346
338347 if ( Object . keys ( dbPatch ) . length > 0 ) {
339348 dbPatch . updatedAt = new Date ( ) ;
0 commit comments