Skip to content

Commit

Permalink
fix: error and types (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
apalchys authored Sep 10, 2023
1 parent 246e4c1 commit dea8606
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 114 deletions.
7 changes: 4 additions & 3 deletions client/src/modules/CrossCheck/UploadCriteriaJSON.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ export const UploadCriteriaJSON = ({ onLoad }: IUploadCriteriaJSON) => {
fileReader.readAsText(info.file.originFileObj as Blob, 'UTF-8');
fileReader.onload = (e: Event) => {
const target = e.target as Element & { result: string };
const { criteria } = JSON.parse(target.result);
const { criteria } = JSON.parse(target.result) as { criteria: CriteriaDto[] };
const transformedCriteria = criteria?.map((item: CriteriaJSONType) => {
if (item.type === TaskType.Title) {
return { type: item.type, text: item.title };
} else return item;
}
return item;
});
if (!transformedCriteria?.length) {
message.warning(`There is no criteria for downloading`);
return;
}
message.success(`${info.file.name} file uploaded successfully`);
onLoad(transformedCriteria);
onLoad(transformedCriteria as CriteriaDto[]);
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/admin/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function createRecord(values: any) {
tags: values.tags,
skills: values.skills?.map((skill: string) => skill.toLowerCase()),
disciplineId: values.discipline,
attributes: JSON.parse(values.attributes ?? '{}'),
attributes: JSON.parse(values.attributes ?? '{}') as Record<string, unknown>,
};
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/course/mentor/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MentorDashboardProps extends CoursePageProps {
}

function parseToken(token: string): Session {
return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString()) as Session;
}

export const getServerSideProps: GetServerSideProps<{ course: ProfileCourseDto }> = async ctx => {
Expand Down
1 change: 1 addition & 0 deletions client/src/reset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@total-typescript/ts-reset';
6 changes: 5 additions & 1 deletion client/src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export class UserService {
},
});

const { username, discriminator, id } = await response.json();
const { username, discriminator, id } = (await response.json()) as {
username: string;
discriminator: string;
id: string;
};

return {
username,
Expand Down
2 changes: 1 addition & 1 deletion common/models/stage-interview-feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface StageInterviewFeedback {
otherAchievements: string | null;
militaryService: 'served' | 'liable' | 'notLiable' | null;
};
skills: {
skills?: {
[index: string]: any;
htmlCss: {
level: number | null;
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ services:
RSSHCOOL_USERS_CLOUD_USERNAME: ${RSSHCOOL_USERS_CLOUD_USERNAME}
RSSHCOOL_USERS_CLOUD_PASSWORD: ${RSSHCOOL_USERS_CLOUD_PASSWORD}
RSSHCOOL_OPENAI_API_KEY: ${RSSHCOOL_OPENAI_API_KEY}
SENTRY_DSN: ${SENTRY_DSN}
restart: on-failure
networks:
- shared-network
Expand Down
2 changes: 1 addition & 1 deletion nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@nestjs/schematics": "10.0.2",
"@nestjs/testing": "10.1.3",
"@openapitools/openapi-generator-cli": "2.7.0",
"@total-typescript/ts-reset": "0.4.2",
"@sentry/node": "7.68.0",
"@types/cache-manager": "4.0.2",
"@types/cookie-parser": "1.4.3",
"@types/express": "4.17.17",
Expand Down
2 changes: 1 addition & 1 deletion nestjs/src/core/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './entity-not-found.filter';
export * from './unhandled-exceptions.filter';
export * from './sentry.filter';
11 changes: 11 additions & 0 deletions nestjs/src/core/filters/sentry.filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ArgumentsHost, Catch } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import * as Sentry from '@sentry/node';

@Catch()
export class SentryFilter extends BaseExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
Sentry.captureException(exception);
super.catch(exception, host);
}
}
47 changes: 0 additions & 47 deletions nestjs/src/core/filters/unhandled-exceptions.filter.ts

This file was deleted.

6 changes: 3 additions & 3 deletions nestjs/src/courses/interviews/interviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ export class InterviewsService {
* @deprecated - should be removed once Artsiom A. makes migration of the legacy feedback format
*/
private static getInterviewRatings({ skills, programmingTask, resume }: StageInterviewFeedbackJson) {
const commonSkills = Object.values(skills.common).filter(Boolean) as number[];
const dataStructuresSkills = Object.values(skills.dataStructures).filter(Boolean) as number[];
const commonSkills = Object.values(skills?.common ?? {}).filter(Boolean) as number[];
const dataStructuresSkills = Object.values(skills?.dataStructures ?? {}).filter(Boolean) as number[];

const htmlCss = skills.htmlCss.level;
const htmlCss = skills?.htmlCss.level;
const common = commonSkills.reduce((acc, cur) => acc + cur, 0) / commonSkills.length;
const dataStructures = dataStructuresSkills.reduce((acc, cur) => acc + cur, 0) / dataStructuresSkills.length;

Expand Down
16 changes: 7 additions & 9 deletions nestjs/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { BadRequestException, INestApplication, ValidationError, ValidationPipe } from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';
import * as Sentry from '@sentry/node';
import * as cookieParser from 'cookie-parser';
import { Logger } from 'nestjs-pino';
import { CloudApiService } from './cloud-api/cloud-api.service';
import { ConfigService } from './config';
import { EntityNotFoundFilter, UnhandledExceptionsFilter } from './core/filters';
import { EntityNotFoundFilter, SentryFilter } from './core/filters';
import { ValidationFilter } from './core/validation';

export function setupApp(app: INestApplication) {
Expand All @@ -13,11 +11,11 @@ export function setupApp(app: INestApplication) {
app.useLogger(logger);
app.use(cookieParser());

const httpAdapterHost = app.get(HttpAdapterHost);
app.useGlobalFilters(
new UnhandledExceptionsFilter(httpAdapterHost, app.get(CloudApiService), app.get(ConfigService)),
new EntityNotFoundFilter(),
);
if (process.env.SENTRY_DSN) {
Sentry.init({ dsn: process.env.SENTRY_DSN });
}

app.useGlobalFilters(new EntityNotFoundFilter(), new SentryFilter());
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
Expand Down
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"db:down": "docker-compose -f ./setup/docker-compose.yml down"
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.5.1",
"prettier": "3.0.2",
"turbo": "1.10.13"
}
Expand Down
1 change: 1 addition & 0 deletions server/src/reset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@total-typescript/ts-reset';
68 changes: 35 additions & 33 deletions server/src/routes/profile/stage-interview-feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ type FeedbackData = {
maxScore: number;
};

export const getStageInterviewFeedback = async (githubId: string): Promise<StageInterviewDetailedFeedback[]> =>
(
await getRepository(StageInterview)
.createQueryBuilder('stageInterview')
.select('"stageInterview"."decision" AS "decision"')
.addSelect('"stageInterview"."isGoodCandidate" AS "isGoodCandidate"')
.addSelect('"stageInterview"."score" AS "interviewScore"')
.addSelect('"course"."name" AS "courseName"')
.addSelect('"course"."fullName" AS "courseFullName"')
.addSelect('"stageInterviewFeedback"."json" AS "interviewResultJson"')
.addSelect('"stageInterviewFeedback"."updatedDate" AS "interviewFeedbackDate"')
.addSelect('"stageInterviewFeedback"."version" AS "feedbackVersion"')
.addSelect('"userMentor"."firstName" AS "interviewerFirstName"')
.addSelect('"userMentor"."lastName" AS "interviewerLastName"')
.addSelect('"userMentor"."githubId" AS "interviewerGithubId"')
.addSelect('"courseTask"."maxScore" AS "maxScore"')
.leftJoin(Student, 'student', '"student"."id" = "stageInterview"."studentId"')
.leftJoin(User, 'user', '"user"."id" = "student"."userId"')
.leftJoin(Course, 'course', '"course"."id" = "stageInterview"."courseId"')
.leftJoin(
StageInterviewFeedback,
'stageInterviewFeedback',
'"stageInterview"."id" = "stageInterviewFeedback"."stageInterviewId"',
)
.leftJoin(CourseTask, 'courseTask', '"courseTask"."id" = "stageInterview"."courseTaskId"')
.leftJoin(Mentor, 'mentor', '"mentor"."id" = "stageInterview"."mentorId"')
.leftJoin(User, 'userMentor', '"userMentor"."id" = "mentor"."userId"')
.where('"user"."githubId" = :githubId', { githubId })
.andWhere('"stageInterview"."isCompleted" = true')
.orderBy('"course"."updatedDate"', 'ASC')
.getRawMany()
)
export const getStageInterviewFeedback = async (githubId: string): Promise<StageInterviewDetailedFeedback[]> => {
const data = await getRepository(StageInterview)
.createQueryBuilder('stageInterview')
.select('"stageInterview"."decision" AS "decision"')
.addSelect('"stageInterview"."isGoodCandidate" AS "isGoodCandidate"')
.addSelect('"stageInterview"."score" AS "interviewScore"')
.addSelect('"course"."name" AS "courseName"')
.addSelect('"course"."fullName" AS "courseFullName"')
.addSelect('"stageInterviewFeedback"."json" AS "interviewResultJson"')
.addSelect('"stageInterviewFeedback"."updatedDate" AS "interviewFeedbackDate"')
.addSelect('"stageInterviewFeedback"."version" AS "feedbackVersion"')
.addSelect('"userMentor"."firstName" AS "interviewerFirstName"')
.addSelect('"userMentor"."lastName" AS "interviewerLastName"')
.addSelect('"userMentor"."githubId" AS "interviewerGithubId"')
.addSelect('"courseTask"."maxScore" AS "maxScore"')
.leftJoin(Student, 'student', '"student"."id" = "stageInterview"."studentId"')
.leftJoin(User, 'user', '"user"."id" = "student"."userId"')
.leftJoin(Course, 'course', '"course"."id" = "stageInterview"."courseId"')
.leftJoin(
StageInterviewFeedback,
'stageInterviewFeedback',
'"stageInterview"."id" = "stageInterviewFeedback"."stageInterviewId"',
)
.leftJoin(CourseTask, 'courseTask', '"courseTask"."id" = "stageInterview"."courseTaskId"')
.leftJoin(Mentor, 'mentor', '"mentor"."id" = "stageInterview"."mentorId"')
.leftJoin(User, 'userMentor', '"userMentor"."id" = "mentor"."userId"')
.where('"user"."githubId" = :githubId', { githubId })
.andWhere('"stageInterview"."isCompleted" = true')
.orderBy('"course"."updatedDate"', 'ASC')
.getRawMany();

return data
.map((data: FeedbackData) => {
const {
feedbackVersion,
Expand All @@ -67,7 +67,8 @@ export const getStageInterviewFeedback = async (githubId: string): Promise<Stage
interviewResultJson,
maxScore,
} = data;
const feedbackTemplate = JSON.parse(interviewResultJson);
const feedbackTemplate = JSON.parse(interviewResultJson) as any;

const { score, feedback } = !feedbackVersion
? parseLegacyFeedback(feedbackTemplate)
: {
Expand All @@ -92,6 +93,7 @@ export const getStageInterviewFeedback = async (githubId: string): Promise<Stage
};
})
.filter(Boolean);
};

// this is legacy form
function parseLegacyFeedback(interviewResult: StageInterviewFeedbackJson) {
Expand Down
8 changes: 4 additions & 4 deletions server/src/services/stageInterview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { StageInterview, StageInterviewFeedback } from '../models';
import { StageInterviewFeedbackJson } from '../../../common/models';

export function getInterviewRatings({ skills, programmingTask, resume }: StageInterviewFeedbackJson) {
const commonSkills = Object.values(skills.common).filter(Boolean) as number[];
const dataStructuresSkills = Object.values(skills.dataStructures).filter(Boolean) as number[];
const commonSkills = Object.values(skills?.common ?? {}).filter(Boolean) as number[];
const dataStructuresSkills = Object.values(skills?.dataStructures ?? {}).filter(Boolean) as number[];

const htmlCss = skills.htmlCss.level;
const htmlCss = skills?.htmlCss.level;
const common = commonSkills.reduce((acc, cur) => acc + cur, 0) / commonSkills.length;
const dataStructures = dataStructuresSkills.reduce((acc, cur) => acc + cur, 0) / dataStructuresSkills.length;

Expand All @@ -28,7 +28,7 @@ export const getStageInterviewRating = (stageInterviews: StageInterview[]) => {
stageInterviewFeedbacks.map((feedback: StageInterviewFeedback) => ({
date: feedback.updatedDate,
// interviews in new template should have score precalculated
rating: score ?? getInterviewRatings(JSON.parse(feedback.json)).rating,
rating: score ?? getInterviewRatings(JSON.parse(feedback.json) as StageInterviewFeedbackJson).rating,
})),
)
.reduce((acc, cur) => acc.concat(cur), [])
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"RSSHCOOL_PG_PASSWORD",
"RSSHCOOL_PG_USERNAME",
"RSSHCOOL_UI_GCP_MAPS_API_KEY",
"RSSHCOOL_OPENAI_API_KEY"
"RSSHCOOL_OPENAI_API_KEY",
"SENTRY_DSN"
]
},
"lint": {},
Expand Down

0 comments on commit dea8606

Please sign in to comment.