refactor: simplify instructor search to query all instructors without course-specific filtering
This commit is contained in:
parent
f4a12c686b
commit
0641b2547a
3 changed files with 12 additions and 29 deletions
|
|
@ -348,31 +348,16 @@ export class CoursesInstructorService {
|
|||
|
||||
static async searchInstructors(input: SearchInstructorInput): Promise<SearchInstructorResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Validate user is instructor of this course
|
||||
await this.validateCourseInstructor(input.token, input.course_id);
|
||||
jwt.verify(input.token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Get existing instructors of this course
|
||||
const existingInstructors = await prisma.courseInstructor.findMany({
|
||||
where: { course_id: input.course_id },
|
||||
select: { user_id: true }
|
||||
});
|
||||
const existingUserIds = existingInstructors.map(i => i.user_id);
|
||||
|
||||
// Search users by email or username (only instructors role)
|
||||
// Search all instructors by email or username
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
{ email: { contains: input.query, mode: 'insensitive' } },
|
||||
{ username: { contains: input.query, mode: 'insensitive' } },
|
||||
]
|
||||
},
|
||||
{ role: { code: 'instructor' } },
|
||||
{ id: { notIn: existingUserIds } } // Exclude already added instructors
|
||||
]
|
||||
OR: [
|
||||
{ email: { contains: input.query, mode: 'insensitive' } },
|
||||
{ username: { contains: input.query, mode: 'insensitive' } },
|
||||
],
|
||||
role: { code: 'instructor' }
|
||||
},
|
||||
include: {
|
||||
profile: true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue