Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:implement loading student summary using nestjs #2471

Merged
merged 31 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c7078bf
feat: implement nestjs route returning mock data
Alphajax Apr 22, 2024
5925549
feat: implement getting student summary from new api
Alphajax Apr 28, 2024
a749faf
refactor: fix eslint issue
Alphajax Apr 28, 2024
3c9df1c
fix: fixed incorrect display of technical screening results on studen…
Alphajax Apr 29, 2024
75ddc97
refactor: remove unused code
Alphajax Apr 30, 2024
7646422
refactor: remove redundant code
Alphajax Apr 30, 2024
3de8682
refactor: fix linter issue
Alphajax Apr 30, 2024
5729e23
Merge branch 'master' into rs-app-2435
Alphajax Apr 30, 2024
ee77148
fix: fix student summary api response type
Alphajax May 1, 2024
8822c46
fix: throw not found error when student is not found
Alphajax May 1, 2024
80b4128
fix: reactor if-else to ternary operation
Alphajax May 1, 2024
5fe595d
refactor: rewrite database queries
Alphajax May 6, 2024
d39852a
refactor: make function getCurrentTaskScore more readable
Alphajax May 6, 2024
22e5700
refactor:refactor getStudentSummary function return statement
Alphajax May 6, 2024
a1f731b
refactor: update course-student.service.ts imports not to use files f…
Alphajax May 8, 2024
f65574d
Merge branch 'master' into rs-app-2435
Alphajax May 8, 2024
985ef96
Merge branch 'master' into rs-app-2435
AlreadyBored May 18, 2024
a5661db
Merge branch 'master' into rs-app-2435
Alphajax Jun 9, 2024
53f70bb
refactor: use StudentSummaryDto instead of (MentorBasic & MentorContact)
Alphajax Jun 9, 2024
58a88ec
reafactor: remove unused code
Alphajax Jun 9, 2024
c03b0ad
refactor: avoid using 'me' to load student summary data
Alphajax Jun 9, 2024
ecb93ee
refactor: fix syntax error at comment
Alphajax Jun 9, 2024
2281924
refactor: shorten return statement at getStageInterviewRating function
Alphajax Jun 9, 2024
224c2b3
refactor: remove unused import
Alphajax Jun 9, 2024
6fb76a6
refactor: avoid using unnecessary typecast
Alphajax Jun 9, 2024
7cc7edf
refactor: add destructuring to convertToMentorBasic function
Alphajax Jun 9, 2024
8d82bae
refactor: remove types duplication
Alphajax Jun 9, 2024
8a0f92a
refactor: fix eslint error
Alphajax Jun 9, 2024
cc5fe5c
Merge branch 'master' into rs-app-2435
Alphajax Jul 11, 2024
0895d6f
fix: fix merge issues
Alphajax Jul 11, 2024
cbd7f24
refactor: fix eslint issue
Alphajax Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3800,6 +3800,91 @@ export interface MentorStudentDto {
*/
'repoUrl': string | null;
}
/**
*
* @export
* @interface MentorStudentSummaryDto
*/
export interface MentorStudentSummaryDto {
/**
*
* @type {number}
* @memberof MentorStudentSummaryDto
*/
'id': number;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'githubId': string;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'name': string;
/**
*
* @type {boolean}
* @memberof MentorStudentSummaryDto
*/
'isActive': boolean;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'cityName': string;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'countryName': string;
/**
*
* @type {Array<string>}
* @memberof MentorStudentSummaryDto
*/
'students': Array<string>;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsEmail': string | null;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsPhone': string | null;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsSkype': string | null;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsTelegram': string | null;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsNotes': string | null;
/**
*
* @type {string}
* @memberof MentorStudentSummaryDto
*/
'contactsWhatsApp': string | null;
}
/**
*
* @export
Expand Down Expand Up @@ -4344,6 +4429,25 @@ export interface PutInterviewFeedbackDto {
*/
'score'?: number;
}
/**
*
* @export
* @interface ResultDto
*/
export interface ResultDto {
/**
*
* @type {number}
* @memberof ResultDto
*/
'score'?: number;
/**
*
* @type {number}
* @memberof ResultDto
*/
'courseTaskId'?: number;
}
/**
*
* @export
Expand Down Expand Up @@ -5125,6 +5229,49 @@ export interface StudentId {
*/
'id': number;
}
/**
*
* @export
* @interface StudentSummaryDto
*/
export interface StudentSummaryDto {
/**
*
* @type {number}
* @memberof StudentSummaryDto
*/
'totalScore': number;
/**
*
* @type {Array<ResultDto>}
* @memberof StudentSummaryDto
*/
'results': Array<ResultDto>;
/**
*
* @type {boolean}
* @memberof StudentSummaryDto
*/
'isActive': boolean;
/**
*
* @type {MentorStudentSummaryDto}
* @memberof StudentSummaryDto
*/
'mentor': MentorStudentSummaryDto | null;
/**
*
* @type {number}
* @memberof StudentSummaryDto
*/
'rank': number;
/**
*
* @type {string}
* @memberof StudentSummaryDto
*/
'repository': string | null;
}
/**
*
* @export
Expand Down Expand Up @@ -15375,6 +15522,43 @@ export const StudentsApiAxiosParamCreator = function (configuration?: Configurat



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {number} courseId
* @param {string} githubId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getStudentSummary: async (courseId: number, githubId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'courseId' is not null or undefined
assertParamExists('getStudentSummary', 'courseId', courseId)
// verify required parameter 'githubId' is not null or undefined
assertParamExists('getStudentSummary', 'githubId', githubId)
const localVarPath = `/courses/{courseId}/students/{githubId}/summary`
.replace(`{${"courseId"}}`, encodeURIComponent(String(courseId)))
.replace(`{${"githubId"}}`, encodeURIComponent(String(githubId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -15404,6 +15588,17 @@ export const StudentsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.getStudent(studentId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {number} courseId
* @param {string} githubId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getStudentSummary(courseId: number, githubId: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<StudentSummaryDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getStudentSummary(courseId, githubId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

Expand All @@ -15423,6 +15618,16 @@ export const StudentsApiFactory = function (configuration?: Configuration, baseP
getStudent(studentId: number, options?: any): AxiosPromise<StudentDto> {
return localVarFp.getStudent(studentId, options).then((request) => request(axios, basePath));
},
/**
*
* @param {number} courseId
* @param {string} githubId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getStudentSummary(courseId: number, githubId: string, options?: any): AxiosPromise<StudentSummaryDto> {
return localVarFp.getStudentSummary(courseId, githubId, options).then((request) => request(axios, basePath));
},
};
};

Expand All @@ -15443,6 +15648,18 @@ export class StudentsApi extends BaseAPI {
public getStudent(studentId: number, options?: AxiosRequestConfig) {
return StudentsApiFp(this.configuration).getStudent(studentId, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @param {number} courseId
* @param {string} githubId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof StudentsApi
*/
public getStudentSummary(courseId: number, githubId: string, options?: AxiosRequestConfig) {
return StudentsApiFp(this.configuration).getStudentSummary(courseId, githubId, options).then((request) => request(this.axios, this.basePath));
}
}


Expand Down
7 changes: 4 additions & 3 deletions client/src/services/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
CriteriaDto,
CrossCheckMessageDto,
CrossCheckCriteriaDataDto,
StudentsApi,
} from 'api';
import { optionalQueryString } from 'utils/optionalQueryString';
import { Decision } from 'data/interviews/technical-screening';
Expand Down Expand Up @@ -140,6 +141,7 @@ export type SearchStudent = UserBasic & { mentor: UserBasic | null };
const courseTasksApi = new CoursesTasksApi();
const courseEventsApi = new CoursesEventsApi();
const studentsScoreApi = new StudentsScoreApi();
const studentsApi = new StudentsApi();

export class CourseService {
private axios: AxiosInstance;
Expand Down Expand Up @@ -527,8 +529,8 @@ export class CourseService {
}

async getStudentSummary(githubId: string | 'me') {
const result = await this.axios.get(`/student/${githubId}/summary`);
return result.data.data as StudentSummary;
const result = await studentsApi.getStudentSummary(this.courseId, githubId);
return result.data as StudentSummary;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, StudentSummaryDto is pretty same, let's avoid unnecessary typecasts/use really returned response type

Suggested change
return result.data as StudentSummary;
return result.data;

}

async getStudentScore(githubId: string) {
Expand Down Expand Up @@ -658,7 +660,6 @@ export interface StudentSummary {
totalScore: number;
results: { score: number; courseTaskId: number }[];
isActive: boolean;
discord: string;
mentor:
| (MentorBasic & {
contactsEmail?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ export class CourseScheduleService {
...(technicalScreeningResults
.find(task => task.courseTaskId === courseTaskId)
?.stageInterviewFeedbacks.map(feedback => JSON.parse(feedback.json))
.map((json: any) => json?.resume?.score ?? 0) ?? []),
.map((json: any) => {
const resumeScore = json?.resume?.score;
const decisionScore = json?.steps?.decision?.values?.finalScore;
return resumeScore ?? decisionScore ?? 0;
}) ?? []),
);
const currentScore = isFinite(scoreRaw) ? scoreRaw : null;
return currentScore;
Expand Down
46 changes: 46 additions & 0 deletions nestjs/src/courses/course-students/course-students.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Controller, Get, NotFoundException, Param, Req, UseGuards } from '@nestjs/common';
import { ApiBadRequestResponse, ApiForbiddenResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CurrentRequest, DefaultGuard } from '../../auth';
import { StudentSummaryDto } from './dto/student-summary.dto';
import { CourseStudentsService } from './course-students.service';

@Controller('courses/:courseId/students')
@ApiTags('students')
@UseGuards(DefaultGuard)
export class CourseStudentsController {
constructor(private courseStudentService: CourseStudentsService) {}

@Get(':githubId/summary')
@ApiForbiddenResponse()
@ApiBadRequestResponse()
@ApiOkResponse({
type: StudentSummaryDto,
})
@ApiOperation({ operationId: 'getStudentSummary' })
public async getStudentSummary(
@Param('courseId') courseId: number,
@Param('githubId') githubId: string,
@Req() req: CurrentRequest,
) {
const studentGithubId = githubId === 'me' ? req.user.githubId : githubId;
Copy link
Contributor

@AlreadyBored AlreadyBored Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't like this usage of githubId, such profile exists in github (https://github.com/me). Let's replace it with separated param that explicitly means that we should use user's github id


const student = await this.courseStudentService.getStudentByGithubId(courseId, studentGithubId);

if (student === null) {
throw new NotFoundException(`Student with GitHub id ${studentGithubId} not found`);
}
const [score, mentor] = await Promise.all([
this.courseStudentService.getStudentScore(student?.id),
student?.mentorId ? await this.courseStudentService.getMentorWithContacts(student.mentorId) : null,
]);

return new StudentSummaryDto({
totalScore: score?.totalScore,
results: score?.results,
rank: score?.rank,
isActive: !student?.isExpelled && !student?.isFailed,
mentor,
repository: student?.repository ?? null,
});
}
}
Loading
Loading