This repository was archived by the owner on Oct 24, 2025. It is now read-only.
feat: add admin only functions and general optimizations - #10
Merged
Conversation
- Create PasswordUtil utility class with hash() and compare() methods - Uses bcrypt with 10 salt rounds - Centralizes password logic for reusability across auth and user services
- Replace direct bcrypt.compare with PasswordUtil.compare - Remove bcrypt import, add PasswordUtil import - Improves code consistency and maintainability
- Add getAllUsers() method to IUserService interface and implementation - Add email uniqueness validation in createUser() - Implement password hashing using PasswordUtil in createUser() - Add proper error handling for duplicate users
- Add createUserDTO with firstName, lastName, email, password, and role - Add updateUserDTO for partial user updates (firstName, lastName, email) - Refactor naming convention to camelCase (baseUserDTO, studentUserDTO, etc.) - Improves API contract consistency
- Add GET /users endpoint to retrieve all users (admin only) - Add POST /users endpoint to create new users (admin only) - Add PATCH /users/:userId to update user details (admin only) - Add DELETE /users/:userId to delete users (admin only) - All endpoints protected with @roles('admin') decorator - Includes proper validation and error handling
- Add userApi.getAll() to fetch all users - Add userApi.create() to create new users - Add userApi.update() to update user details - Add userApi.delete() to remove users - Add userApi.separateByRole() helper to split users by role - All methods include proper error handling and TypeScript typing
- Create Dialog component with accessibility features (Escape key, overlay) - Add DialogContent, DialogHeader, DialogTitle, DialogDescription subcomponents - Add DialogFooter for action buttons - Handles body scroll lock when dialog is open - Styled with Tailwind CSS and theme-aware
- Add UserCard: displays user details with edit/delete actions - Add UserList: renders list of users with add button - Add UserTabs: tabbed interface for students/teachers - Add UserFormDialog: form for creating/editing users - Components support both students and teachers - Shows role-specific data (favorites for students, modules for teachers)
- Complete CRUD functionality for users - Separate tabs for students and teachers - Create, edit, and delete user operations - Real-time state updates after mutations - Proper loading states and error handling - Toast notifications for user feedback - Confirmation dialogs for destructive actions
- Add /users route for UserManagement page (admin only) - Add /admin route for AdminDashboard page (admin only) - Both routes protected with ProtectedRoute and RoleProtectedRoute - Import AdminDashboard and UserManagement components
- Add 'Users' link to header (visible to admins only) - Add 'Recommendations' link to header (visible to students only) - Implement role-based filtering in navigation rendering - Add NavItem interface with optional roles property
- Update JSDoc comment for better clarity - Specify 'current authenticated user' instead of generic 'user data' - Minor documentation improvement
…button in Electives page
Restructure the many-to-many relationship between teachers and electives by moving ownership from Teacher.modulesGiven[] to Elective.teachers[]. This improves query performance and domain semantics by making electives the aggregate root that owns the relationship. Changes: - Add teachers[] array to Elective model and schema - Remove modulesGiven[] from Teacher model and schema - Move assign/unassign logic from TeacherService to ElectiveService - Add findByTeacherId() method to ElectiveRepository - Update TeacherService.getElectivesGiven() to query by teacher ID - Update UserService to check electives when deleting teachers - Update frontend types and Profile component to fetch electives - Update UserCard component to remove modulesGiven display BREAKING CHANGE: Teacher.modulesGiven[] no longer exists. Use Elective.teachers[] or ElectiveRepository.findByTeacherId() instead.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This pull request introduces significant improvements to how electives and teachers are managed, centralizes password handling, and streamlines user and teacher-related logic. The most important changes are grouped below:
Elective-Teacher Assignment and Data Model
assignTeacherToElectiveandunassignTeacherFromElectivemethods toIElectiveService, with full implementation inElectiveService, allowing teachers to be assigned or unassigned from electives with proper validation. (apps/backend/src/application/ports/elective.port.ts[1]apps/backend/src/application/services/elective.service.ts[2]Electivedomain model and Mongoose schema to include ateachersfield (array of teacher IDs), and removed themodulesGivenfield fromTeacherUserand the teacher schema, shifting the relationship to be managed on the elective side. (apps/backend/src/domain/elective/elective.ts[1]apps/backend/src/domain/user/user.ts[2]apps/backend/src/infrastructure/mongoose/schemas/elective.schema.ts[3]apps/backend/src/infrastructure/mongoose/schemas/teacher.schema.ts[4]Repository and Query Enhancements
findByTeacherIdtoIElectiveRepositoryand implemented it in the Mongoose repository, enabling efficient queries for electives by teacher assignment. Also updated create/update logic to handle teacher IDs as ObjectIds. (apps/backend/src/domain/elective/elective.repository.interface.ts[1]apps/backend/src/infrastructure/mongoose/repositories/mongoose-elective.repository.ts[2] [3]TeacherServiceto use the new repository method, simplifying logic when fetching electives taught by a teacher. (apps/backend/src/application/services/teacher.service.ts[1] [2]User and Authentication Improvements
PasswordUtilutility, replacing direct bcrypt usage in services and ensuring consistent password handling. (apps/backend/src/application/utils/password.util.ts[1]apps/backend/src/application/services/auth.service.ts[2] [3]apps/backend/src/application/services/user.service.ts[4]UserServiceto prevent duplicate user creation by checking for existing emails, and to restrict deletion of teachers who are assigned to electives using the new assignment model. (apps/backend/src/application/services/user.service.ts[1] [2]API and Controller Updates
IUserServiceand its implementation. (apps/backend/src/application/ports/user.port.ts[1]apps/backend/src/application/services/user.service.ts[2]AuthGuardandRolesGuardfor enhanced security. (apps/backend/src/interfaces/controllers/elective.controller.ts[1] [2]These changes collectively modernize the way electives and teachers are related, improve security and maintainability, and streamline service and repository logic.