Skip to content

Commit

Permalink
feat: add "wearecommunityUrl"
Browse files Browse the repository at this point in the history
  • Loading branch information
apalchys committed Jan 9, 2025
1 parent 0a051db commit a576b00
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 27 deletions.
32 changes: 31 additions & 1 deletion client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,12 @@ export interface CourseDto {
* @memberof CourseDto
*/
'certificateThreshold': number;
/**
*
* @type {string}
* @memberof CourseDto
*/
'wearecommunityUrl': string | null;
}
/**
*
Expand Down Expand Up @@ -1882,7 +1888,13 @@ export interface CreateCourseDto {
* @type {string}
* @memberof CreateCourseDto
*/
'description': string;
'description'?: string;
/**
*
* @type {string}
* @memberof CreateCourseDto
*/
'descriptionUrl'?: string;
/**
*
* @type {number}
Expand Down Expand Up @@ -1931,6 +1943,12 @@ export interface CreateCourseDto {
* @memberof CreateCourseDto
*/
'certificateThreshold': number;
/**
*
* @type {string}
* @memberof CreateCourseDto
*/
'wearecommunityUrl': string;
}
/**
*
Expand Down Expand Up @@ -4812,6 +4830,12 @@ export interface ProfileCourseDto {
* @memberof ProfileCourseDto
*/
'certificateThreshold': number;
/**
*
* @type {string}
* @memberof ProfileCourseDto
*/
'wearecommunityUrl': string | null;
}
/**
*
Expand Down Expand Up @@ -6609,6 +6633,12 @@ export interface UpdateCourseDto {
* @memberof UpdateCourseDto
*/
'certificateThreshold': number;
/**
*
* @type {string}
* @memberof UpdateCourseDto
*/
'wearecommunityUrl'?: string | null;
}
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import utc from 'dayjs/plugin/utc';
import { Course } from 'services/models';
dayjs.extend(utc);

const courseApi = new CoursesApi();
const wearecommunityRegex = new RegExp('^(https?://)?(www\\.)?wearecommunity\\.io.*$');

const courseApi = new CoursesApi();
const courseIcons = Object.entries(DEFAULT_COURSE_ICONS).map(([key, config]) => ({ ...config, id: key }));

type CourseModalProps = {
Expand Down Expand Up @@ -47,6 +48,7 @@ type FormData = {
certificateIssuer?: string;
discipline?: { id: number } | null;
courseId?: number;
wearecommunityUrl?: string;
};

export function CourseModal(props: CourseModalProps) {
Expand Down Expand Up @@ -290,6 +292,18 @@ export function CourseModal(props: CourseModalProps) {
</Col>
</Row>

<Row gutter={24}>
<Col sm={12} span={24}>
<Form.Item
rules={[{ message: 'Please enter wearecommunity.io URL', pattern: wearecommunityRegex }]}
name="wearecommunityUrl"
label="wearecommunity.io URL"
>
<Input />
</Form.Item>
</Col>
</Row>

<Form.Item name="usePrivateRepositories" valuePropName="checked">
<Checkbox>Use Private Repositories</Checkbox>
</Form.Item>
Expand Down Expand Up @@ -328,13 +342,15 @@ function createRecord(values: FormData) {
logo: values.logo,
minStudentsPerMentor: values.minStudentsPerMentor,
certificateThreshold: values.certificateThreshold,
wearecommunityUrl: values.wearecommunityUrl,
};
return record;
}

function getInitialValues(modalData: Partial<Course>): FormData {
return {
...modalData,
wearecommunityUrl: modalData.wearecommunityUrl ?? undefined,
minStudentsPerMentor: modalData.minStudentsPerMentor || 2,
certificateThreshold: modalData.certificateThreshold ?? 70,
inviteOnly: !!modalData.inviteOnly,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { PublicLink } from './index';

const mockUrl = 'https://expample.com';
Expand Down Expand Up @@ -40,11 +40,9 @@ describe('PublicLink', () => {

fireEvent.click(copyBtn);

await waitFor(() => {
expect(mockCopyToClipboard).toHaveBeenCalledWith(mockUrl);
});

const notification = screen.getByText('Copied to clipboard');
const notification = await screen.findByText('Copied to clipboard');
expect(notification).toBeInTheDocument();

expect(mockCopyToClipboard).toHaveBeenCalledWith(mockUrl);
});
});
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 @@ -27,6 +27,7 @@ export class CourseDto {
this.discipline = course.discipline ? { id: course.discipline.id, name: course.discipline.name } : null;
this.minStudentsPerMentor = course.minStudentsPerMentor;
this.certificateThreshold = course.certificateThreshold;
this.wearecommunityUrl = course.wearecommunityUrl;
}

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

@ApiProperty()
certificateThreshold: number;

@ApiProperty({ nullable: true, type: String })
wearecommunityUrl: string | null;
}
5 changes: 5 additions & 0 deletions nestjs/src/courses/dto/create-course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ export class CreateCourseDto {
@IsNumber()
@ApiProperty({ required: true })
certificateThreshold: number;

@IsString()
@IsOptional()
@ApiProperty()
wearecommunityUrl?: string;
}
2 changes: 2 additions & 0 deletions nestjs/src/courses/dto/export-course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ExportCourseDto {
this.description = course.description;
this.descriptionUrl = course.descriptionUrl;
this.registrationEndDate = course.registrationEndDate?.toISOString() ?? null;
this.wearecommunityUrl = course.wearecommunityUrl || null;
}

id: number;
Expand All @@ -24,4 +25,5 @@ export class ExportCourseDto {
registrationEndDate: string | null;
startDate: string;
endDate: string;
wearecommunityUrl: string | null;
}
5 changes: 5 additions & 0 deletions nestjs/src/courses/dto/update-course.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ export class UpdateCourseDto {
@IsNumber()
@ApiProperty({ required: true })
certificateThreshold: number;

@IsString()
@IsOptional()
@ApiPropertyOptional({ nullable: true, type: 'string' })
wearecommunityUrl?: string | null;
}
33 changes: 20 additions & 13 deletions nestjs/src/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,12 @@
"/courses/{courseId}/interviews/{interviewId}/register": {
"post": {
"operationId": "registerToInterview",
"summary": "",
"parameters": [
{ "name": "courseId", "required": true, "in": "path", "schema": { "type": "number" } },
{ "name": "interviewId", "required": true, "in": "path", "schema": { "type": "number" } }
],
"responses": { "200": { "description": "" }, "400": { "description": "" }, "403": { "description": "" } },
"summary": "",
"tags": ["courses interviews"]
}
},
Expand Down Expand Up @@ -2685,7 +2685,6 @@
"/contributors": {
"post": {
"operationId": "createContributor",
"summary": "",
"parameters": [],
"requestBody": {
"required": true,
Expand All @@ -2697,11 +2696,11 @@
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContributorDto" } } }
}
},
"summary": "",
"tags": ["contributors"]
},
"get": {
"operationId": "getContributors",
"summary": "",
"parameters": [],
"responses": {
"200": {
Expand All @@ -2713,32 +2712,32 @@
}
}
},
"summary": "",
"tags": ["contributors"]
}
},
"/contributors/{id}": {
"get": {
"operationId": "getContributor",
"summary": "",
"parameters": [{ "name": "id", "required": true, "in": "path", "schema": { "type": "number" } }],
"responses": {
"200": {
"description": "",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContributorDto" } } }
}
},
"summary": "",
"tags": ["contributors"]
},
"delete": {
"operationId": "deleteContributor",
"summary": "",
"parameters": [{ "name": "id", "required": true, "in": "path", "schema": { "type": "number" } }],
"responses": { "200": { "description": "" } },
"summary": "",
"tags": ["contributors"]
},
"patch": {
"operationId": "updateContributor",
"summary": "",
"parameters": [{ "name": "id", "required": true, "in": "path", "schema": { "type": "number" } }],
"requestBody": {
"required": true,
Expand All @@ -2750,6 +2749,7 @@
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContributorDto" } } }
}
},
"summary": "",
"tags": ["contributors"]
}
}
Expand Down Expand Up @@ -2943,7 +2943,8 @@
"logo": { "type": "string" },
"discipline": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/IdNameDto" }] },
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
"certificateThreshold": { "type": "number" },
"wearecommunityUrl": { "type": "string", "nullable": true }
},
"required": [
"id",
Expand Down Expand Up @@ -2971,7 +2972,8 @@
"logo",
"discipline",
"minStudentsPerMentor",
"certificateThreshold"
"certificateThreshold",
"wearecommunityUrl"
]
},
"CreateCourseDto": {
Expand All @@ -2987,16 +2989,18 @@
"planned": { "type": "boolean" },
"inviteOnly": { "type": "boolean" },
"description": { "type": "string" },
"descriptionUrl": { "type": "string" },
"disciplineId": { "type": "number" },
"discordServerId": { "type": "number" },
"usePrivateRepositories": { "type": "boolean" },
"certificateIssuer": { "type": "string" },
"personalMentoring": { "type": "boolean" },
"logo": { "type": "string" },
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
"certificateThreshold": { "type": "number" },
"wearecommunityUrl": { "type": "string" }
},
"required": ["name", "startDate", "endDate", "fullName", "alias", "description", "certificateThreshold"]
"required": ["name", "startDate", "endDate", "fullName", "alias", "certificateThreshold", "wearecommunityUrl"]
},
"UpdateCourseDto": {
"type": "object",
Expand All @@ -3021,7 +3025,8 @@
"logo": { "type": "string" },
"disciplineId": { "type": "number" },
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
"certificateThreshold": { "type": "number" },
"wearecommunityUrl": { "type": "string", "nullable": true }
},
"required": ["certificateThreshold"]
},
Expand Down Expand Up @@ -4441,7 +4446,8 @@
"logo": { "type": "string" },
"discipline": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/IdNameDto" }] },
"minStudentsPerMentor": { "type": "number" },
"certificateThreshold": { "type": "number" }
"certificateThreshold": { "type": "number" },
"wearecommunityUrl": { "type": "string", "nullable": true }
},
"required": [
"id",
Expand Down Expand Up @@ -4469,7 +4475,8 @@
"logo",
"discipline",
"minStudentsPerMentor",
"certificateThreshold"
"certificateThreshold",
"wearecommunityUrl"
]
},
"UpdateUserDto": {
Expand Down
13 changes: 13 additions & 0 deletions server/src/migrations/1736458672717-Course.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "course" ADD "wearecommunityUrl" character varying`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "course" DROP COLUMN "wearecommunityUrl"`);
}
}
2 changes: 2 additions & 0 deletions server/src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { Obfuscation1700391857109 } from './1700391857109-Obfuscation';
import { Course1712137476312 } from './1712137476312-Course';
import { CourseTask1730926720293 } from './1730926720293-CourseTask';
import { Contributor1734874453585 } from './1734874453585-Contributor';
import { Course1736458672717 } from './1736458672717-Course';

export const migrations = [
UserMigration1630340371992,
Expand Down Expand Up @@ -118,4 +119,5 @@ export const migrations = [
Course1712137476312,
CourseTask1730926720293,
Contributor1734874453585,
Course1736458672717,
];
3 changes: 3 additions & 0 deletions server/src/models/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ export class Course {

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

@Column({ nullable: true, type: 'varchar' })
wearecommunityUrl: string | null;
}
Loading

0 comments on commit a576b00

Please sign in to comment.