refactor: reorder searchInstructors endpoint and fix role code to uppercase INSTRUCTOR, add lesson completion tracking on quiz pass

This commit is contained in:
JakkrapartXD 2026-01-29 16:39:33 +07:00
parent 8e57cb124a
commit 24c37df4ef
3 changed files with 39 additions and 17 deletions

View file

@ -43,6 +43,21 @@ export class CoursesInstructorController {
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
@ -197,21 +212,6 @@ export class CoursesInstructorController {
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)
* Add a new instructor to the course (using email or username)

View file

@ -357,7 +357,7 @@ export class CoursesInstructorService {
{ email: { contains: input.query, mode: 'insensitive' } },
{ username: { contains: input.query, mode: 'insensitive' } },
],
role: { code: 'instructor' }
role: { code: 'INSTRUCTOR' }
},
include: {
profile: true
@ -407,7 +407,7 @@ export class CoursesInstructorService {
{ email: addinstructorCourse.email_or_username },
{ username: addinstructorCourse.email_or_username },
],
role: { code: 'instructor' }
role: { code: 'INSTRUCTOR' }
}
});

View file

@ -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 {
code: 200,
message: isPassed ? 'Quiz passed!' : 'Quiz completed',