Add Phase 4b: instructor blocked dates, store closures, and substitute instructors

- New tables: instructor_blocked_date, store_closure (migration 0034)
- substitute_instructor_id column added to lesson_session
- Session generation skips blocked instructor dates and store closure periods
- Substitute assignment validates sub is not blocked and has no conflicting slot
- Routes: POST/GET/DELETE /instructors/:id/blocked-dates, POST/GET/DELETE /store-closures
- 15 new integration tests covering blocked dates, store closures, and sub validation
This commit is contained in:
Ryan Moon
2026-03-30 10:29:13 -05:00
parent aae5a022a8
commit 5cd2d05983
8 changed files with 541 additions and 6 deletions

View File

@@ -18,8 +18,10 @@ import {
LessonPlanCreateSchema,
LessonPlanUpdateSchema,
LessonPlanItemUpdateSchema,
InstructorBlockedDateCreateSchema,
StoreClosureCreateSchema,
} from '@lunarfront/shared/schemas'
import { InstructorService, LessonTypeService, ScheduleSlotService, EnrollmentService, LessonSessionService, GradingScaleService, LessonPlanService, LessonPlanItemService } from '../../services/lesson.service.js'
import { InstructorService, LessonTypeService, ScheduleSlotService, EnrollmentService, LessonSessionService, GradingScaleService, LessonPlanService, LessonPlanItemService, InstructorBlockedDateService, StoreClosureService } from '../../services/lesson.service.js'
export const lessonRoutes: FastifyPluginAsync = async (app) => {
// --- Instructors ---
@@ -252,9 +254,10 @@ export const lessonRoutes: FastifyPluginAsync = async (app) => {
if (!parsed.success) {
return reply.status(400).send({ error: { message: 'Validation failed', details: parsed.error.flatten(), statusCode: 400 } })
}
const session = await LessonSessionService.update(app.db, id, parsed.data)
if (!session) return reply.status(404).send({ error: { message: 'Lesson session not found', statusCode: 404 } })
return reply.send(session)
const result = await LessonSessionService.update(app.db, id, parsed.data)
if (!result) return reply.status(404).send({ error: { message: 'Lesson session not found', statusCode: 404 } })
if ('error' in result) return reply.status(409).send({ error: { message: result.error, statusCode: 409 } })
return reply.send(result)
})
app.post('/lesson-sessions/:id/status', { preHandler: [app.authenticate, app.requirePermission('lessons.edit')] }, async (request, reply) => {
@@ -379,4 +382,58 @@ export const lessonRoutes: FastifyPluginAsync = async (app) => {
if (!item) return reply.status(404).send({ error: { message: 'Lesson plan item not found', statusCode: 404 } })
return reply.send(item)
})
// --- Instructor Blocked Dates ---
app.post('/instructors/:id/blocked-dates', { preHandler: [app.authenticate, app.requirePermission('lessons.admin')] }, async (request, reply) => {
const { id } = request.params as { id: string }
const parsed = InstructorBlockedDateCreateSchema.safeParse(request.body)
if (!parsed.success) {
return reply.status(400).send({ error: { message: 'Validation failed', details: parsed.error.flatten(), statusCode: 400 } })
}
const instructor = await InstructorService.getById(app.db, id)
if (!instructor) return reply.status(404).send({ error: { message: 'Instructor not found', statusCode: 404 } })
const result = await InstructorBlockedDateService.create(app.db, id, parsed.data)
if ('error' in result) return reply.status(409).send({ error: { message: result.error, statusCode: 409 } })
return reply.status(201).send(result)
})
app.get('/instructors/:id/blocked-dates', { preHandler: [app.authenticate, app.requirePermission('lessons.view')] }, async (request, reply) => {
const { id } = request.params as { id: string }
const instructor = await InstructorService.getById(app.db, id)
if (!instructor) return reply.status(404).send({ error: { message: 'Instructor not found', statusCode: 404 } })
const dates = await InstructorBlockedDateService.list(app.db, id)
return reply.send(dates)
})
app.delete('/instructors/:instructorId/blocked-dates/:id', { preHandler: [app.authenticate, app.requirePermission('lessons.admin')] }, async (request, reply) => {
const { instructorId, id } = request.params as { instructorId: string; id: string }
const row = await InstructorBlockedDateService.delete(app.db, id, instructorId)
if (!row) return reply.status(404).send({ error: { message: 'Blocked date not found', statusCode: 404 } })
return reply.send(row)
})
// --- Store Closures ---
app.post('/store-closures', { preHandler: [app.authenticate, app.requirePermission('lessons.admin')] }, async (request, reply) => {
const parsed = StoreClosureCreateSchema.safeParse(request.body)
if (!parsed.success) {
return reply.status(400).send({ error: { message: 'Validation failed', details: parsed.error.flatten(), statusCode: 400 } })
}
const result = await StoreClosureService.create(app.db, parsed.data)
if ('error' in result) return reply.status(409).send({ error: { message: result.error, statusCode: 409 } })
return reply.status(201).send(result)
})
app.get('/store-closures', { preHandler: [app.authenticate, app.requirePermission('lessons.view')] }, async (_request, reply) => {
const closures = await StoreClosureService.list(app.db)
return reply.send(closures)
})
app.delete('/store-closures/:id', { preHandler: [app.authenticate, app.requirePermission('lessons.admin')] }, async (request, reply) => {
const { id } = request.params as { id: string }
const row = await StoreClosureService.delete(app.db, id)
if (!row) return reply.status(404).send({ error: { message: 'Store closure not found', statusCode: 404 } })
return reply.send(row)
})
}