feat: Add instructor capabilities to update, delete, and submit courses for review.

This commit is contained in:
JakkrapartXD 2026-01-16 17:36:32 +07:00
parent 38648581ec
commit 2e536ad193
3 changed files with 268 additions and 16 deletions

View file

@ -11,7 +11,11 @@ import {
removeinstructorCourse,
removeinstructorCourseResponse,
setprimaryCourseInstructor,
setprimaryCourseInstructorResponse
setprimaryCourseInstructorResponse,
UpdateMyCourse,
UpdateMyCourseResponse,
DeleteMyCourseResponse,
submitCourseResponse
} from '../types/CoursesInstructor.types';
import { CreateCourseValidator } from "../validators/CoursesInstructor.validator";
@ -45,7 +49,20 @@ export class CoursesInstructorController {
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.getmyCourse(token, courseId);
return await CoursesInstructorService.getmyCourse({ token, course_id: courseId });
}
@Put('{courseId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Course updated successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Course not found')
public async updateCourse(@Request() request: any, @Path() courseId: number, @Body() body: UpdateMyCourse): Promise<UpdateMyCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.updateCourse(token, courseId, body.data);
}
@Post('')
@ -54,12 +71,38 @@ export class CoursesInstructorController {
@Response('400', 'Validation error')
@Response('500', 'Internal server error')
public async createCourse(@Body() body: createCourses, @Request() request: any): Promise<createCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
const { error, value } = CreateCourseValidator.validate(body.data);
if (error) throw new ValidationError(error.details[0].message);
const course = await CoursesInstructorService.createCourse(value, decoded.id);
return course;
const token = request.headers.authorization?.replace('Bearer ', '');
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
const { error, value } = CreateCourseValidator.validate(body.data);
if (error) throw new ValidationError(error.details[0].message);
const course = await CoursesInstructorService.createCourse(value, decoded.id);
return course;
}
@Delete('{courseId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Course deleted successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Course not found')
public async deleteCourse(@Request() request: any, @Path() courseId: number): Promise<DeleteMyCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.deleteCourse(token, courseId);
}
@Post('send-review/{courseId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Course submitted successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Course not found')
public async submitCourse(@Request() request: any, @Path() courseId: number): Promise<submitCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.sendCourseForReview({ token, course_id: courseId });
}