feat: Introduce API endpoints and refactor service methods for adding, removing, listing, and setting primary course instructors.
This commit is contained in:
parent
2e536ad193
commit
b5ca6b2e0f
3 changed files with 66 additions and 8 deletions
|
|
@ -15,7 +15,8 @@ import {
|
|||
UpdateMyCourse,
|
||||
UpdateMyCourseResponse,
|
||||
DeleteMyCourseResponse,
|
||||
submitCourseResponse
|
||||
submitCourseResponse,
|
||||
listinstructorCourseResponse
|
||||
} from '../types/CoursesInstructor.types';
|
||||
import { CreateCourseValidator } from "../validators/CoursesInstructor.validator";
|
||||
|
||||
|
|
@ -105,5 +106,55 @@ export class CoursesInstructorController {
|
|||
return await CoursesInstructorService.sendCourseForReview({ token, course_id: courseId });
|
||||
}
|
||||
|
||||
@Get('listinstructor/{courseId}')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Instructors retrieved successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructors not found')
|
||||
public async listInstructorCourses(@Request() request: any, @Path() courseId: number): Promise<listinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
|
||||
}
|
||||
|
||||
@Post('add-instructor/{courseId}/{userId}')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Instructor added successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructor not found')
|
||||
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<addinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.addInstructorToCourse({ token, course_id: courseId, user_id: userId });
|
||||
}
|
||||
|
||||
@Post('remove-instructor/{courseId}/{userId}')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Instructor removed successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructor not found')
|
||||
public async removeInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<removeinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.removeInstructorFromCourse({ token, course_id: courseId, user_id: userId });
|
||||
}
|
||||
|
||||
@Post('set-primary-instructor/{courseId}/{userId}')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Primary instructor set successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Primary instructor not found')
|
||||
public async setPrimaryInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<setprimaryCourseInstructorResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.setPrimaryInstructor({ token, course_id: courseId, user_id: userId });
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,8 @@ import {
|
|||
submitCourseResponse,
|
||||
listinstructorCourseResponse,
|
||||
sendCourseForReview,
|
||||
getmyCourse
|
||||
getmyCourse,
|
||||
listinstructorCourse,
|
||||
} from "../types/CoursesInstructor.types";
|
||||
|
||||
export class CoursesInstructorService {
|
||||
|
|
@ -186,7 +187,7 @@ export class CoursesInstructorService {
|
|||
|
||||
|
||||
|
||||
async addInstructorToCourse(addinstructorCourse: addinstructorCourse): Promise<addinstructorCourseResponse> {
|
||||
static async addInstructorToCourse(addinstructorCourse: addinstructorCourse): Promise<addinstructorCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(addinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseInstructor.create({
|
||||
|
|
@ -205,7 +206,7 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
async removeInstructorFromCourse(removeinstructorCourse: removeinstructorCourse): Promise<removeinstructorCourseResponse> {
|
||||
static async removeInstructorFromCourse(removeinstructorCourse: removeinstructorCourse): Promise<removeinstructorCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(removeinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseInstructor.delete({
|
||||
|
|
@ -226,12 +227,12 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
async listInstructorsOfCourse(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<listinstructorCourseResponse> {
|
||||
static async listInstructorsOfCourse(listinstructorCourse: listinstructorCourse): Promise<listinstructorCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(setprimaryCourseInstructor.token, config.jwt.secret) as { id: number; type: string };
|
||||
const decoded = jwt.verify(listinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
const courseInstructors = await prisma.courseInstructor.findMany({
|
||||
where: {
|
||||
course_id: setprimaryCourseInstructor.course_id,
|
||||
course_id: listinstructorCourse.course_id,
|
||||
},
|
||||
include: {
|
||||
user: true,
|
||||
|
|
@ -248,7 +249,7 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
async setPrimaryInstructor(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<setprimaryCourseInstructorResponse> {
|
||||
static async setPrimaryInstructor(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<setprimaryCourseInstructorResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(setprimaryCourseInstructor.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseInstructor.update({
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ export interface listCourseinstructorResponse {
|
|||
|
||||
export interface addinstructorCourse {
|
||||
token: string;
|
||||
user_id: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +120,11 @@ export interface listinstructorCourseResponse {
|
|||
}[];
|
||||
}
|
||||
|
||||
export interface listinstructorCourse {
|
||||
token: string;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
export interface removeinstructorCourse {
|
||||
token: string;
|
||||
user_id: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue