Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Put, | |
| Delete, | |
| Param, | |
| Body, | |
| UseGuards, | |
| HttpCode, | |
| ParseIntPipe, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiBearerAuth, | |
| ApiParam, | |
| ApiBody, | |
| } from '@nestjs/swagger'; | |
| import { ProgramService } from '../services/program.service'; | |
| import { | |
| CreateProgramDto, | |
| UpdateProgramDto, | |
| ProgramDto, | |
| } from '../dtos/program.dto'; | |
| import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../../auth/guards/roles.guard'; | |
| import { Roles } from '../../auth/roles.decorator'; | |
| import { RoleName } from '../../auth/entities/role.entity'; | |
| ('📚 Programs') | |
| ('api') | |
| (JwtAuthGuard, RolesGuard) | |
| ('JWT-auth') | |
| export class ProgramController { | |
| constructor(private readonly programService: ProgramService) {} | |
| ('departments/:deptId/programs') | |
| ( | |
| RoleName.IT_ADMIN, | |
| RoleName.ADMIN, | |
| RoleName.INSTRUCTOR, | |
| RoleName.TA, | |
| RoleName.STUDENT, | |
| ) | |
| ({ | |
| summary: 'List programs by department', | |
| description: ` | |
| ## List Programs in Department | |
| Retrieves all academic programs belonging to a specific department. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles Required**: All roles (STUDENT, INSTRUCTOR, TA, ADMIN, IT_ADMIN) | |
| `, | |
| }) | |
| ({ name: 'deptId', description: 'Department ID', type: Number }) | |
| ({ status: 200, description: 'List of programs' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 404, description: 'Department not found' }) | |
| async findByDepartmentId( | |
| ('deptId', ParseIntPipe) deptId: number, | |
| ): Promise<ProgramDto[]> { | |
| return this.programService.findByDepartmentId(deptId) as Promise< | |
| ProgramDto[] | |
| >; | |
| } | |
| ('programs') | |
| (RoleName.IT_ADMIN, RoleName.ADMIN) | |
| (201) | |
| ({ | |
| summary: 'Create new program', | |
| description: ` | |
| ## Create New Academic Program | |
| Creates a new academic program within a department. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles Required**: ADMIN, IT_ADMIN only | |
| ### Program Types | |
| - Bachelor's, Master's, PhD, Certificate, etc. | |
| `, | |
| }) | |
| ({ type: CreateProgramDto }) | |
| ({ status: 201, description: 'Program created successfully' }) | |
| ({ status: 400, description: 'Invalid input data' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden - Admin access required' }) | |
| async create(() dto: CreateProgramDto): Promise<ProgramDto> { | |
| return this.programService.create(dto) as Promise<ProgramDto>; | |
| } | |
| ('programs/:id') | |
| ( | |
| RoleName.IT_ADMIN, | |
| RoleName.ADMIN, | |
| RoleName.INSTRUCTOR, | |
| RoleName.TA, | |
| RoleName.STUDENT, | |
| ) | |
| ({ | |
| summary: 'Get program by ID', | |
| description: ` | |
| ## Get Program Details | |
| Retrieves details of a specific academic program. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles Required**: All roles (STUDENT, INSTRUCTOR, TA, ADMIN, IT_ADMIN) | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Program ID', type: Number }) | |
| ({ status: 200, description: 'Program details' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 404, description: 'Program not found' }) | |
| async findById(('id', ParseIntPipe) id: number): Promise<ProgramDto> { | |
| return this.programService.findById(id) as Promise<ProgramDto>; | |
| } | |
| ('programs/:id') | |
| (RoleName.IT_ADMIN, RoleName.ADMIN) | |
| ({ | |
| summary: 'Update program', | |
| description: ` | |
| ## Update Academic Program | |
| Updates an existing academic program. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles Required**: ADMIN, IT_ADMIN only | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Program ID', type: Number }) | |
| ({ type: UpdateProgramDto }) | |
| ({ status: 200, description: 'Program updated successfully' }) | |
| ({ status: 400, description: 'Invalid input data' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden - Admin access required' }) | |
| ({ status: 404, description: 'Program not found' }) | |
| async update( | |
| ('id', ParseIntPipe) id: number, | |
| () dto: UpdateProgramDto, | |
| ): Promise<ProgramDto> { | |
| return this.programService.update(id, dto) as Promise<ProgramDto>; | |
| } | |
| ('programs/:id') | |
| (RoleName.IT_ADMIN, RoleName.ADMIN) | |
| (204) | |
| ({ | |
| summary: 'Delete program', | |
| description: ` | |
| ## Delete Academic Program | |
| Deletes an academic program from the system. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token) | |
| - **Roles Required**: ADMIN, IT_ADMIN only | |
| ### ⚠️ Warning | |
| Programs with enrolled students cannot be deleted. | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Program ID', type: Number }) | |
| ({ status: 204, description: 'Program deleted successfully' }) | |
| ({ status: 400, description: 'Cannot delete program with students' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden - Admin access required' }) | |
| ({ status: 404, description: 'Program not found' }) | |
| async delete(('id', ParseIntPipe) id: number): Promise<void> { | |
| return this.programService.delete(id); | |
| } | |
| } | |