feat: update instructor search to exclude self and existing course instructors, add email_verified_at to user responses
Update searchInstructors endpoint to accept courseId parameter and filter out the requesting instructor and instructors already assigned to the course. Add email_verified_at field to UserResponse type and include it in auth and user service responses.
This commit is contained in:
parent
80d7372dfa
commit
48e8f56e22
6 changed files with 29 additions and 8 deletions
|
|
@ -356,16 +356,26 @@ export class CoursesInstructorService {
|
|||
|
||||
static async searchInstructors(input: SearchInstructorInput): Promise<SearchInstructorResponse> {
|
||||
try {
|
||||
jwt.verify(input.token, config.jwt.secret) as { id: number };
|
||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Search all instructors by email or username
|
||||
// Get existing instructors in the course
|
||||
const existingInstructors = await prisma.courseInstructor.findMany({
|
||||
where: { course_id: input.course_id },
|
||||
select: { user_id: true },
|
||||
});
|
||||
const existingInstructorIds = existingInstructors.map(i => i.user_id);
|
||||
|
||||
// Search all instructors by email or username, excluding self and existing course instructors
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ email: { contains: input.query, mode: 'insensitive' } },
|
||||
{ username: { contains: input.query, mode: 'insensitive' } },
|
||||
],
|
||||
role: { code: 'INSTRUCTOR' }
|
||||
role: { code: 'INSTRUCTOR' },
|
||||
id: {
|
||||
notIn: [decoded.id, ...existingInstructorIds],
|
||||
},
|
||||
},
|
||||
include: {
|
||||
profile: true
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ export class AuthService {
|
|||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
email_verified_at: user.email_verified_at,
|
||||
updated_at: user.updated_at,
|
||||
created_at: user.created_at,
|
||||
role: {
|
||||
|
|
@ -423,6 +424,7 @@ export class AuthService {
|
|||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
email_verified_at: user.email_verified_at,
|
||||
updated_at: user.updated_at,
|
||||
created_at: user.created_at,
|
||||
role: {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export class UserService {
|
|||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
email_verified_at: user.email_verified_at,
|
||||
updated_at: user.updated_at,
|
||||
created_at: user.created_at,
|
||||
role: {
|
||||
|
|
@ -285,6 +286,7 @@ export class UserService {
|
|||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
email_verified_at: user.email_verified_at,
|
||||
updated_at: user.updated_at,
|
||||
created_at: user.created_at,
|
||||
role: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue