Skip to content

Commit

Permalink
feat: add a new field certificateThreshold to the Course data model (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski committed Apr 10, 2024
1 parent 6ae9ab2 commit e4cff04
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 18 deletions.
15 changes: 15 additions & 0 deletions client/specs/smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ test.describe('Home', () => {
const href = await page.locator('css=a >> text="Score"').getAttribute('href');
expect(href?.includes('/course/score')).toBeTruthy();
});

test('should navigate to Courses page and verify threshold', async ({ page }) => {
await page.click('span[role="img"][aria-label="menu-unfold"]');

await page.click('text=Admin Area');

const coursesLink = page.locator('text=Courses');
await expect(coursesLink).toBeVisible();
await coursesLink.click();

await page.getByRole('button', { name: /add course/i }).click();

const certificateThreshold = page.locator('input#certificateThreshold');
await expect(certificateThreshold).toHaveValue('70');
});
});
24 changes: 24 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ export interface CourseDto {
* @memberof CourseDto
*/
'minStudentsPerMentor': number;
/**
*
* @type {number}
* @memberof CourseDto
*/
'certificateThreshold': number;
}
/**
*
Expand Down Expand Up @@ -1586,6 +1592,12 @@ export interface CreateCourseDto {
* @memberof CreateCourseDto
*/
'minStudentsPerMentor'?: number;
/**
*
* @type {number}
* @memberof CreateCourseDto
*/
'certificateThreshold': number;
}
/**
*
Expand Down Expand Up @@ -4224,6 +4236,12 @@ export interface ProfileCourseDto {
* @memberof ProfileCourseDto
*/
'minStudentsPerMentor': number;
/**
*
* @type {number}
* @memberof ProfileCourseDto
*/
'certificateThreshold': number;
}
/**
*
Expand Down Expand Up @@ -5803,6 +5821,12 @@ export interface UpdateCourseDto {
* @memberof UpdateCourseDto
*/
'minStudentsPerMentor'?: number;
/**
*
* @type {number}
* @memberof UpdateCourseDto
*/
'certificateThreshold': number;
}
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const StudentsWithMentorsCard = ({ studentsStats }: Props) => {
return (
<Card title="Students With Mentor">
<Text strong>
Students With Mentor: {studentsStats.studentsWithMentorCount} / {studentsStats.totalStudents}
Students With Mentor: {studentsStats.studentsWithMentorCount} / {studentsStats.activeStudentsCount}
</Text>
<div style={{ height: 180, width: '100%' }}>
<MentorsStatsChart
count={studentsStats.studentsWithMentorCount}
total={studentsStats.totalStudents}
total={studentsStats.activeStudentsCount}
color={Colors.Gold}
/>
</div>
Expand Down
40 changes: 33 additions & 7 deletions client/src/pages/admin/courses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,37 @@ function Page() {
</Select>
</Form.Item>

<Form.Item
name="minStudentsPerMentor"
label="Minimum Students per Mentor"
rules={[{ min: 1, type: 'integer', message: 'Ensure that the input, if provided, is a positive integer.' }]}
>
<InputNumber step={1} />
</Form.Item>
<Row>
<Col span={12}>
<Form.Item
name="minStudentsPerMentor"
label="Minimum Students per Mentor"
rules={[
{ min: 1, type: 'integer', message: 'Ensure that the input, if provided, is a positive integer.' },
]}
>
<InputNumber step={1} />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
name="certificateThreshold"
label="Certificate Threshold"
tooltip="Minimum score percentage required for students to qualify for a certificate."
rules={[
{
required: true,
message: 'Please input the certificate threshold.',
type: 'integer',
min: 1,
max: 100,
},
]}
>
<InputNumber step={5} min={1} max={100} addonAfter="%" />
</Form.Item>
</Col>
</Row>

<Form.Item name="state" label="State">
<Radio.Group>
Expand Down Expand Up @@ -310,6 +334,7 @@ function createRecord(values: any) {
personalMentoring: values.personalMentoring,
logo: values.logo,
minStudentsPerMentor: values.minStudentsPerMentor,
certificateThreshold: values.certificateThreshold,
};
return record;
}
Expand Down Expand Up @@ -390,6 +415,7 @@ function getInitialValues(modalData: Partial<Course>) {
return {
...modalData,
minStudentsPerMentor: modalData.minStudentsPerMentor || 2,
certificateThreshold: modalData.certificateThreshold ?? 70,
inviteOnly: !!modalData.inviteOnly,
state: modalData.completed ? 'completed' : modalData.planned ? 'planned' : 'active',
registrationEndDate: modalData.registrationEndDate ? dayjs.utc(modalData.registrationEndDate) : null,
Expand Down
4 changes: 4 additions & 0 deletions nestjs/src/courses/dto/course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class CourseDto {
this.logo = course.logo;
this.discipline = course.discipline ? { id: course.discipline.id, name: course.discipline.name } : null;
this.minStudentsPerMentor = course.minStudentsPerMentor;
this.certificateThreshold = course.certificateThreshold;
}

@ApiProperty()
Expand Down Expand Up @@ -102,4 +103,7 @@ export class CourseDto {

@ApiProperty()
minStudentsPerMentor: number;

@ApiProperty()
certificateThreshold: number;
}
4 changes: 4 additions & 0 deletions nestjs/src/courses/dto/create-course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ export class CreateCourseDto {
@IsOptional()
@ApiProperty({ required: false })
minStudentsPerMentor?: number;

@IsNumber()
@ApiProperty({ required: true })
certificateThreshold: number;
}
4 changes: 4 additions & 0 deletions nestjs/src/courses/dto/update-course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ export class UpdateCourseDto {
@IsOptional()
@ApiPropertyOptional()
minStudentsPerMentor?: number;

@IsNumber()
@ApiProperty({ required: true })
certificateThreshold: number;
}
1 change: 0 additions & 1 deletion nestjs/src/courses/interviews/interviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class InterviewsService {
.where('is.courseId = :courseId', { courseId })
.andWhere('is.courseTaskId = :courseTaskId', { courseTaskId })
.andWhere('student.isExpelled = false')
.andWhere('student.isExpelled = false')
.andWhere('taskChecker.id IS NULL')
.orderBy('student.totalScore', 'DESC')
.getMany();
Expand Down
22 changes: 14 additions & 8 deletions nestjs/src/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,8 @@
"personalMentoring": { "type": "boolean" },
"logo": { "type": "string" },
"discipline": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/IdNameDto" }] },
"minStudentsPerMentor": { "type": "number" }
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
},
"required": [
"id",
Expand All @@ -2647,7 +2648,8 @@
"personalMentoring",
"logo",
"discipline",
"minStudentsPerMentor"
"minStudentsPerMentor",
"certificateThreshold"
]
},
"CreateCourseDto": {
Expand All @@ -2669,9 +2671,10 @@
"certificateIssuer": { "type": "string" },
"personalMentoring": { "type": "boolean" },
"logo": { "type": "string" },
"minStudentsPerMentor": { "type": "number" }
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
},
"required": ["name", "startDate", "endDate", "fullName", "alias", "description"]
"required": ["name", "startDate", "endDate", "fullName", "alias", "description", "certificateThreshold"]
},
"UpdateCourseDto": {
"type": "object",
Expand All @@ -2694,9 +2697,10 @@
"personalMentoring": { "type": "boolean" },
"logo": { "type": "string" },
"disciplineId": { "type": "number" },
"minStudentsPerMentor": { "type": "number" }
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
},
"required": ["name", "fullName", "alias"]
"required": ["name", "fullName", "alias", "certificateThreshold"]
},
"LeaveCourseRequestDto": { "type": "object", "properties": { "comment": { "type": "string" } } },
"StudentDto": {
Expand Down Expand Up @@ -3861,7 +3865,8 @@
"personalMentoring": { "type": "boolean" },
"logo": { "type": "string" },
"discipline": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/IdNameDto" }] },
"minStudentsPerMentor": { "type": "number" }
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
},
"required": [
"id",
Expand All @@ -3888,7 +3893,8 @@
"personalMentoring",
"logo",
"discipline",
"minStudentsPerMentor"
"minStudentsPerMentor",
"certificateThreshold"
]
},
"UpdateUserDto": {
Expand Down
13 changes: 13 additions & 0 deletions server/src/migrations/1712137476312-Course.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class Course1712137476312 implements MigrationInterface {
name = 'Course1712137476312';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "course" ADD "certificateThreshold" integer DEFAULT '70'`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "course" DROP COLUMN "certificateThreshold"`);
}
}
2 changes: 2 additions & 0 deletions server/src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { InterviewScore1686657350908 } from './1686657350908-InterviewScore';
import { CourseUsersActivist1693930286280 } from './1693930286280-CourseUsersActivist';
import { AddMinStudentPerMentorColumnToCourse1699808604000 } from './1699808604000-AddMinStudentPerMentorColumnToCourse';
import { Obfuscation1700391857109 } from './1700391857109-Obfuscation';
import { Course1712137476312 } from './1712137476312-Course';

export const migrations = [
UserMigration1630340371992,
Expand Down Expand Up @@ -112,4 +113,5 @@ export const migrations = [
CourseUsersActivist1693930286280,
AddMinStudentPerMentorColumnToCourse1699808604000,
Obfuscation1700391857109,
Course1712137476312,
];
3 changes: 3 additions & 0 deletions server/src/models/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@ export class Course {

@Column({ default: 2, nullable: true })
minStudentsPerMentor: number;

@Column({ default: 70 })
certificateThreshold: number;
}

0 comments on commit e4cff04

Please sign in to comment.