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: Refactor JudgingSession to include title property #623

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/api/src/api/expoJudgingSession/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const post = async (req: Request, res: Response) => {
try {
expoJudgingSession = new ExpoJudgingSession({
createdBy: admin.user,
title: 'Expo Judging Session',
});

const projects = await entityManager.find(Project, { id: { $in: data.projectIds } });
Expand Down
1 change: 1 addition & 0 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"migration:create": "mikro-orm migration:create",
"migration:up": "mikro-orm migration:up",
"migration:down": "mikro-orm migration:down",
"migration:fresh": "yarn mikro-orm migration:fresh --drop-db",
"seed": "yarn mikro-orm migration:fresh --seed DatabaseSeeder",
"typecheck": "tsc",
"test": "jest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ExpoJudgingSessionSeeder extends Seeder {
for (let i = 0; i < numSessions; i += 1) {
const expoJudgingSession = new ExpoJudgingSession({
createdBy: ref(admin),
title: `Expo Judging Session ${i + 1}`,
});
expoJudgingSession.projects.set(projects);

Expand Down
6 changes: 1 addition & 5 deletions packages/database/src/entities/CriteriaJudgingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ type ConstructorArgs = ConstructorValues<

@Entity()
export class CriteriaJudgingSession extends JudgingSession {
@Property({ columnType: 'text' })
title: string;

@Property({ columnType: 'text' })
description: string;

@ManyToMany({ entity: () => Criteria })
criteriaList = new Collection<Criteria>(this);

constructor({ title, description, createdBy }: ConstructorArgs) {
super({ createdBy });
super({ title, createdBy });

this.title = title;
this.description = description;
}
}
6 changes: 5 additions & 1 deletion packages/database/src/entities/JudgingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export type JudgingSessionConstructorValues = ConstructorValues<
>;

export abstract class JudgingSession extends Node<JudgingSession> {
@Property({ columnType: 'text' })
title: string;

@Property({ unique: true })
inviteCode: string = v4();

Expand All @@ -22,9 +25,10 @@ export abstract class JudgingSession extends Node<JudgingSession> {
@ManyToMany({ entity: () => Project })
projects = new Collection<Project>(this);

constructor({ createdBy }: JudgingSessionConstructorValues) {
constructor({ title, createdBy }: JudgingSessionConstructorValues) {
super();

this.title = title;
this.createdBy = createdBy;
}
}
27 changes: 18 additions & 9 deletions packages/database/src/migrations/.snapshot-hangar.json
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,15 @@
"default": "clock_timestamp()",
"mappedType": "datetime"
},
"title": {
"name": "title",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"inviteCode": {
"name": "inviteCode",
"type": "varchar(255)",
Expand Down Expand Up @@ -1132,6 +1141,15 @@
"default": "clock_timestamp()",
"mappedType": "datetime"
},
"title": {
"name": "title",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"inviteCode": {
"name": "inviteCode",
"type": "varchar(255)",
Expand All @@ -1150,15 +1168,6 @@
"nullable": false,
"mappedType": "bigint"
},
"title": {
"name": "title",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"description": {
"name": "description",
"type": "text",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20231218190523 extends Migration {

async up(): Promise<void> {
this.addSql('alter table "ExpoJudgingSession" add column "title" text not null;');
}

async down(): Promise<void> {
this.addSql('alter table "ExpoJudgingSession" drop column "title";');
}

}
Loading