Skip to content

Commit 4ba0624

Browse files
committed
validate only pending sessions can have their timeslots modified
1 parent c672344 commit 4ba0624

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

app/scheduling/actions.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,16 @@ export async function selectAvailabilities(
121121
return result.state;
122122
}
123123

124-
// 4. Update the session
124+
// 4. Only pending sessions can have their availabilities changed
125+
if (result.session.status !== "pending") {
126+
return {
127+
errors: {
128+
_form: ["Availabilities can only be set for pending sessions"],
129+
},
130+
};
131+
}
132+
133+
// 5. Update the session
125134
try {
126135
await db
127136
.update(coachingSessions)
@@ -184,7 +193,16 @@ export async function selectTimeSlot(
184193

185194
const { session } = result;
186195

187-
// 4. Verify the slot exists in the session's available time slots
196+
// 4. Only pending sessions can be confirmed
197+
if (session.status !== "pending") {
198+
return {
199+
errors: {
200+
_form: ["Only pending sessions can be confirmed"],
201+
},
202+
};
203+
}
204+
205+
// 5. Verify the slot exists in the session's available time slots
188206
const slots = session.selectedTimeSlots as TimeSlot[] | null;
189207
if (!slots || !Array.isArray(slots)) {
190208
return {

0 commit comments

Comments
 (0)