feat(timetable): replace the hard-coded weekly schedule with a real timetable module (fixes #251) - #256
Open
MOHITKOURAV01 wants to merge 2 commits into
Conversation
WeeklyClassSchedule rendered five fake periods from an array literal, so every student in every class saw the same made-up week and no teacher could change it. - Add Timetable model with HH:mm period validation and a pre-validate hook that rejects overlapping periods and duplicate period numbers - Add periodsForDay/currentPeriod/findClash helpers so the controller and the UI agree on what "now" and "clash" mean - Add timetableController with CRUD, per-period add/update/remove, activate (which deactivates the class's previous live timetable), and resolved /me and /today views - Add /api/timetables routes with teacher and admin guards - Add TimetablePanel dashboard tab that flags clashes before saving - Add /timetable page: weekly grid, mobile day picker, live period highlight and a print stylesheet - Make WeeklyClassSchedule read the API and fall back to the sample week only when nothing is published Fixes Sitaram8472#251
Mongoose 9 no longer passes a `next` callback to document middleware, so
both callback-style pre('validate') hooks resolved without running their
checks — overlapping and duplicate periods were silently accepted.
Convert both hooks to async functions that throw.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Closes #251.
frontend/src/components/WeeklyClassSchedule.jsxrendered five fake periods from an array literal inside the component, so every student in every class saw the same made-up week, no teacher could change it, and a day could only ever have one period. This PR adds a real timetable module and points the widget at it.Backend
backend/models/Timetable.jsperiods[]withHH:mmvalidation, a pre-validate hook rejecting overlaps and duplicate period numbers, plusperiodsForDay(),currentPeriod()andfindClash()backend/controllers/timetableController.js/meand/todayviewsbackend/routes/timetableRoutes.js/api/timetables, teacher and admin guardedEndpoints
Frontend
components/teacher/TimetablePanel.jsx— a new Timetable tab on the Teacher Dashboard: create a grid for a class, add periods day by day with type (lecture/lab/activity/break/exam) and room, and publish it. Clashes are detected client-side before the request so an obvious mistake is reported instantly.pages/Timetable.jsx—/timetable. Full six-day grid on desktop, a day picker on mobile, a live "happening now" highlight that re-ticks every minute, weekly statistics, and a print stylesheet.components/WeeklyClassSchedule.jsx— now fetches the active timetable and renders every period per day, falling back to the original sample week (clearly labelled as a sample) only when nothing is published or the API is unreachable, so the student dashboard never breaks.Design notes
HH:mmstrings compared as minutes since midnight. That keeps the model free of timezones and makes overlap arithmetic trivially correct.findClash()is exposed on the model so the single-period endpoint can answer without re-validating the whole document, and the panel can preview the same rule client-side. One rule, three call sites.userFacingflag, so the controller can return400for those and keep500for genuine bugs, rather than blanket-converting every thrown error into a client error./meresolves by role: a student gets their class grid, a teacher gets the periods they personally teach across every live class.Verification
The validation rules were exercised directly:
Plus
node --checkon every file, routers mounting on a real Express app, a cleanvite build, and no new eslint errors.Note on Mongoose 9
The project is on
mongoose@^9.4.1, which no longer passes anextcallback to document middleware — a callback-stylepre('validate')hook resolves without running its body, which would have made the overlap checks silently no-ops. Both hooks areasyncfunctions; the second commit fixes this after it was caught in testing. Worth knowing for any other PR adding a model to this repo.Compatibility
The only change to existing code is
WeeklyClassSchedulegaining a data source, and it still renders when signed out or offline.server.jsgains two lines,App.jsxone route,TeacherDashboard.jsxone tab.