refactor: reorder searchInstructors endpoint and fix role code to uppercase INSTRUCTOR, add lesson completion tracking on quiz pass
This commit is contained in:
parent
8e57cb124a
commit
24c37df4ef
3 changed files with 39 additions and 17 deletions
|
|
@ -43,6 +43,21 @@ export class CoursesInstructorController {
|
||||||
return await CoursesInstructorService.listMyCourses(token);
|
return await CoursesInstructorService.listMyCourses(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ค้นหาผู้สอนทั้งหมดในระบบ
|
||||||
|
* Search all instructors in database
|
||||||
|
* @param query - คำค้นหา (email หรือ username) / Search query (email or username)
|
||||||
|
*/
|
||||||
|
@Get('search-instructors')
|
||||||
|
@Security('jwt', ['instructor'])
|
||||||
|
@SuccessResponse('200', 'Instructors found')
|
||||||
|
@Response('401', 'Invalid or expired token')
|
||||||
|
public async searchInstructors(@Request() request: any, @Query() query: string): Promise<SearchInstructorResponse> {
|
||||||
|
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||||
|
if (!token) throw new ValidationError('No token provided');
|
||||||
|
return await CoursesInstructorService.searchInstructors({ token, query });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ดึงข้อมูลคอร์สเฉพาะของผู้สอน (พร้อมบทเรียนและเนื้อหา)
|
* ดึงข้อมูลคอร์สเฉพาะของผู้สอน (พร้อมบทเรียนและเนื้อหา)
|
||||||
* Get detailed course information including chapters, lessons, attachments, and quizzes
|
* Get detailed course information including chapters, lessons, attachments, and quizzes
|
||||||
|
|
@ -197,21 +212,6 @@ export class CoursesInstructorController {
|
||||||
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
|
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ค้นหาผู้สอนทั้งหมดในระบบ
|
|
||||||
* Search all instructors in database
|
|
||||||
* @param query - คำค้นหา (email หรือ username) / Search query (email or username)
|
|
||||||
*/
|
|
||||||
@Get('search-instructors')
|
|
||||||
@Security('jwt', ['instructor'])
|
|
||||||
@SuccessResponse('200', 'Instructors found')
|
|
||||||
@Response('401', 'Invalid or expired token')
|
|
||||||
public async searchInstructors(@Request() request: any, @Query() query: string): Promise<SearchInstructorResponse> {
|
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.searchInstructors({ token, query });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* เพิ่มผู้สอนเข้าในคอร์ส (ใช้ email หรือ username)
|
* เพิ่มผู้สอนเข้าในคอร์ส (ใช้ email หรือ username)
|
||||||
* Add a new instructor to the course (using email or username)
|
* Add a new instructor to the course (using email or username)
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,7 @@ export class CoursesInstructorService {
|
||||||
{ email: { contains: input.query, mode: 'insensitive' } },
|
{ email: { contains: input.query, mode: 'insensitive' } },
|
||||||
{ username: { contains: input.query, mode: 'insensitive' } },
|
{ username: { contains: input.query, mode: 'insensitive' } },
|
||||||
],
|
],
|
||||||
role: { code: 'instructor' }
|
role: { code: 'INSTRUCTOR' }
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
profile: true
|
profile: true
|
||||||
|
|
@ -407,7 +407,7 @@ export class CoursesInstructorService {
|
||||||
{ email: addinstructorCourse.email_or_username },
|
{ email: addinstructorCourse.email_or_username },
|
||||||
{ username: addinstructorCourse.email_or_username },
|
{ username: addinstructorCourse.email_or_username },
|
||||||
],
|
],
|
||||||
role: { code: 'instructor' }
|
role: { code: 'INSTRUCTOR' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1169,6 +1169,28 @@ export class CoursesStudentService {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If passed, upsert lesson_progress to mark lesson as completed
|
||||||
|
if (isPassed) {
|
||||||
|
await prisma.lessonProgress.upsert({
|
||||||
|
where: {
|
||||||
|
user_id_lesson_id: {
|
||||||
|
user_id: decoded.id,
|
||||||
|
lesson_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
user_id: decoded.id,
|
||||||
|
lesson_id,
|
||||||
|
is_completed: true,
|
||||||
|
completed_at: now,
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
is_completed: true,
|
||||||
|
completed_at: now,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: isPassed ? 'Quiz passed!' : 'Quiz completed',
|
message: isPassed ? 'Quiz passed!' : 'Quiz completed',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue