Skip to content

Commit

Permalink
fix: update access to students (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski authored Feb 13, 2024
1 parent 1e380e9 commit 33d34fa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nestjs/src/courses/students/students.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { AuthUser, Role, CourseRole } from '../../auth';
import { Repository } from 'typeorm';
import { StageInterview } from '@entities/index';

@Injectable()
export class StudentsService {
constructor(
@InjectRepository(Student)
readonly studentRepository: Repository<Student>,

@InjectRepository(StageInterview)
readonly stageInterviewRepository: Repository<StageInterview>,
) {}

public getById(id: number) {
Expand All @@ -17,6 +21,7 @@ export class StudentsService {

public async canAccessStudent(user: AuthUser, studentId: number): Promise<boolean> {
const student = await this.studentRepository.findOneBy({ id: studentId });
const stageInterviews = await this.stageInterviewRepository.find({ where: { studentId } });
if (student == null) {
return false;
}
Expand All @@ -37,6 +42,10 @@ export class StudentsService {
return true;
}

if (stageInterviews.some(interview => interview.mentorId === currentMentorId)) {
return true;
}

if (student.mentorId == null) {
return false;
}
Expand Down

0 comments on commit 33d34fa

Please sign in to comment.