Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Query, | |
| Param, | |
| Req, | |
| UseGuards, | |
| ParseIntPipe, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiParam, | |
| ApiResponse, | |
| ApiBearerAuth, | |
| ApiQuery, | |
| } from '@nestjs/swagger'; | |
| import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../../auth/guards/roles.guard'; | |
| import { ScheduleService } from '../services'; | |
| import { QueryScheduleDto } from '../dto'; | |
| ('📅 Schedule') | |
| ('JWT-auth') | |
| ('api/schedule') | |
| (JwtAuthGuard, RolesGuard) | |
| export class ScheduleController { | |
| constructor(private readonly scheduleService: ScheduleService) {} | |
| ('my/daily') | |
| ({ | |
| summary: 'Get my daily schedule', | |
| description: ` | |
| ## Get Today's Schedule | |
| Returns the current user's schedule for today (or specified date), aggregating: | |
| - **Class schedules** from enrolled/taught courses | |
| - **Calendar events** (personal and course-related) | |
| - **Exams** scheduled for the day | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles**: ALL (Student, Instructor, TA, Admin) | |
| ### Role-Based Filtering | |
| - **Students**: See schedules for enrolled courses only | |
| - **Instructors**: See schedules for courses they teach | |
| - **TAs**: See schedules for courses they assist | |
| - **Admins**: See all schedules | |
| `, | |
| }) | |
| ({ | |
| name: 'date', | |
| required: false, | |
| type: String, | |
| description: 'Date in YYYY-MM-DD format (defaults to today)', | |
| example: '2026-04-15', | |
| }) | |
| ({ status: 200, description: 'Daily schedule retrieved successfully' }) | |
| ({ status: 401, description: 'Unauthorized - Invalid or missing token' }) | |
| async getDailySchedule(('date') date: string, () req: any) { | |
| const userId = req.user.userId || req.user.id; | |
| const roles = this.extractRoles(req.user); | |
| return this.scheduleService.getDailySchedule(userId, roles, date); | |
| } | |
| ('my/weekly') | |
| ({ | |
| summary: 'Get my weekly schedule', | |
| description: ` | |
| ## Get Weekly Schedule | |
| Returns the current user's schedule for the week, aggregating daily schedules. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles**: ALL (Student, Instructor, TA, Admin) | |
| ### Response Structure | |
| Returns 7 days starting from Monday of the current week (or specified start date). | |
| `, | |
| }) | |
| ({ | |
| name: 'startDate', | |
| required: false, | |
| type: String, | |
| description: 'Start date of week in YYYY-MM-DD format', | |
| example: '2026-04-13', | |
| }) | |
| ({ status: 200, description: 'Weekly schedule retrieved successfully' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| async getWeeklySchedule(('startDate') startDate: string, () req: any) { | |
| const userId = req.user.userId || req.user.id; | |
| const roles = this.extractRoles(req.user); | |
| return this.scheduleService.getWeeklySchedule(userId, roles, startDate); | |
| } | |
| ('range') | |
| ({ | |
| summary: 'Get schedule for date range', | |
| description: ` | |
| ## Get Schedule Range | |
| Returns events and exams within a specified date range with optional filtering. | |
| ### Query Parameters | |
| - \`startDate\`: Start of range (YYYY-MM-DD) | |
| - \`endDate\`: End of range (YYYY-MM-DD) | |
| - \`eventType\`: Filter by event type | |
| - \`courseId\`: Filter by specific course | |
| `, | |
| }) | |
| ({ status: 200, description: 'Schedule range retrieved successfully' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| async getScheduleRange(() query: QueryScheduleDto, () req: any) { | |
| const userId = req.user.userId || req.user.id; | |
| const roles = this.extractRoles(req.user); | |
| return this.scheduleService.getScheduleRange(userId, roles, query); | |
| } | |
| ('section/:sectionId') | |
| ({ | |
| summary: 'Get section schedule', | |
| description: ` | |
| ## Get Section Schedule | |
| Returns all class meeting times for a specific course section. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles**: ALL | |
| `, | |
| }) | |
| ({ | |
| name: 'sectionId', | |
| description: 'Course section ID', | |
| type: Number, | |
| example: 1, | |
| }) | |
| ({ status: 200, description: 'Section schedule retrieved successfully' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async getSectionSchedule(('sectionId', ParseIntPipe) sectionId: number) { | |
| return this.scheduleService.getSectionSchedule(sectionId); | |
| } | |
| ('academic') | |
| ({ | |
| summary: 'Get academic calendar', | |
| description: ` | |
| ## Get Academic Calendar | |
| Returns academic calendar with important dates, exam schedules, and semester milestones. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles**: ALL | |
| `, | |
| }) | |
| ({ | |
| name: 'semesterId', | |
| required: false, | |
| type: Number, | |
| description: 'Filter by semester ID', | |
| example: 1, | |
| }) | |
| ({ status: 200, description: 'Academic calendar retrieved successfully' }) | |
| async getAcademicCalendar(('semesterId') semesterId?: number) { | |
| return this.scheduleService.getAcademicCalendar(semesterId); | |
| } | |
| private extractRoles(user: any): string[] { | |
| if (Array.isArray(user.roles)) { | |
| return user.roles.map((r: any) => (typeof r === 'string' ? r : r.name || r.roleName)); | |
| } | |
| return []; | |
| } | |
| } | |