feat: Introduce API endpoints and refactor service methods for adding, removing, listing, and setting primary course instructors.

This commit is contained in:
JakkrapartXD 2026-01-16 17:52:36 +07:00
parent 2e536ad193
commit b5ca6b2e0f
3 changed files with 66 additions and 8 deletions

View file

@ -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({