Add Phase 7: grade history and session-plan item linking
- New tables: lesson_plan_item_grade_history (append-only), lesson_session_plan_item - Grading an item updates current_grade_value and creates immutable history record - Grading a not_started item auto-transitions it to in_progress - Linking items to a session also auto-transitions not_started items - Link operation is idempotent — re-linking same items produces no duplicates - Endpoints: POST/GET /lesson-plan-items/:id/grades, GET /lesson-plan-items/:id/grade-history - Endpoints: POST/GET /lesson-sessions/:id/plan-items - 8 new integration tests
This commit is contained in:
@@ -18,10 +18,12 @@ import {
|
||||
LessonPlanCreateSchema,
|
||||
LessonPlanUpdateSchema,
|
||||
LessonPlanItemUpdateSchema,
|
||||
GradeCreateSchema,
|
||||
SessionPlanItemsSchema,
|
||||
InstructorBlockedDateCreateSchema,
|
||||
StoreClosureCreateSchema,
|
||||
} from '@lunarfront/shared/schemas'
|
||||
import { InstructorService, LessonTypeService, ScheduleSlotService, EnrollmentService, LessonSessionService, GradingScaleService, LessonPlanService, LessonPlanItemService, InstructorBlockedDateService, StoreClosureService } from '../../services/lesson.service.js'
|
||||
import { InstructorService, LessonTypeService, ScheduleSlotService, EnrollmentService, LessonSessionService, GradingScaleService, LessonPlanService, LessonPlanItemService, GradeHistoryService, SessionPlanItemService, InstructorBlockedDateService, StoreClosureService } from '../../services/lesson.service.js'
|
||||
|
||||
export const lessonRoutes: FastifyPluginAsync = async (app) => {
|
||||
// --- Instructors ---
|
||||
@@ -383,6 +385,44 @@ export const lessonRoutes: FastifyPluginAsync = async (app) => {
|
||||
return reply.send(item)
|
||||
})
|
||||
|
||||
// --- Grade History ---
|
||||
|
||||
app.post('/lesson-plan-items/:id/grades', { preHandler: [app.authenticate, app.requirePermission('lessons.edit')] }, async (request, reply) => {
|
||||
const { id } = request.params as { id: string }
|
||||
const parsed = GradeCreateSchema.safeParse(request.body)
|
||||
if (!parsed.success) {
|
||||
return reply.status(400).send({ error: { message: 'Validation failed', details: parsed.error.flatten(), statusCode: 400 } })
|
||||
}
|
||||
const result = await GradeHistoryService.create(app.db, id, parsed.data, request.user.id)
|
||||
if (!result) return reply.status(404).send({ error: { message: 'Lesson plan item not found', statusCode: 404 } })
|
||||
return reply.status(201).send(result)
|
||||
})
|
||||
|
||||
app.get('/lesson-plan-items/:id/grade-history', { preHandler: [app.authenticate, app.requirePermission('lessons.view')] }, async (request, reply) => {
|
||||
const { id } = request.params as { id: string }
|
||||
const history = await GradeHistoryService.list(app.db, id)
|
||||
return reply.send(history)
|
||||
})
|
||||
|
||||
// --- Session Plan Items ---
|
||||
|
||||
app.post('/lesson-sessions/:id/plan-items', { preHandler: [app.authenticate, app.requirePermission('lessons.edit')] }, async (request, reply) => {
|
||||
const { id } = request.params as { id: string }
|
||||
const parsed = SessionPlanItemsSchema.safeParse(request.body)
|
||||
if (!parsed.success) {
|
||||
return reply.status(400).send({ error: { message: 'Validation failed', details: parsed.error.flatten(), statusCode: 400 } })
|
||||
}
|
||||
const result = await SessionPlanItemService.linkItems(app.db, id, parsed.data)
|
||||
if (result === null) return reply.status(404).send({ error: { message: 'Lesson session not found', statusCode: 404 } })
|
||||
return reply.status(201).send({ linked: result.length, items: result })
|
||||
})
|
||||
|
||||
app.get('/lesson-sessions/:id/plan-items', { preHandler: [app.authenticate, app.requirePermission('lessons.view')] }, async (request, reply) => {
|
||||
const { id } = request.params as { id: string }
|
||||
const items = await SessionPlanItemService.listForSession(app.db, id)
|
||||
return reply.send(items)
|
||||
})
|
||||
|
||||
// --- Instructor Blocked Dates ---
|
||||
|
||||
app.post('/instructors/:id/blocked-dates', { preHandler: [app.authenticate, app.requirePermission('lessons.admin')] }, async (request, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user