Skip to content

Commit f5592ca

Browse files
committed
database entities
1 parent b447fde commit f5592ca

6 files changed

Lines changed: 65 additions & 11 deletions

File tree

backend/src/entities/criteria.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
2+
import { Longtext } from "./longtext";
3+
4+
@Entity()
5+
export class Criteria {
6+
@PrimaryGeneratedColumn()
7+
public readonly id!: number;
8+
@Column({ length: 1024 })
9+
public title!: string;
10+
@Longtext()
11+
public description!: string;
12+
}
13+
14+
// TODO Rating Project and Criteria DTO

backend/src/entities/longtext.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Column } from "typeorm";
2+
3+
export function Longtext() {
4+
// Sqlite doesn't support longtext. I hate this, but it is what it is if we want
5+
// to keep backend tests and prepare tilt for the upcoming Hackaburg as quickly
6+
// as possible.
7+
if (process.env.NODE_ENV === "test") {
8+
return Column("text");
9+
}
10+
return Column("longtext");
11+
}

backend/src/entities/project.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
2+
import { Longtext } from "./longtext";
3+
import { Team } from "./team";
4+
5+
@Entity()
6+
export class Project {
7+
@PrimaryGeneratedColumn()
8+
public readonly id!: number;
9+
@OneToOne(() => Team, { eager: true })
10+
public team!: Team;
11+
@Column({ length: 1024 })
12+
public title!: string;
13+
@Longtext()
14+
public description!: string;
15+
@Column()
16+
public allowRating!: boolean;
17+
}

backend/src/entities/rating.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
2+
import { Criteria } from "./criteria";
3+
import { Project } from "./project";
4+
import { User } from "./user";
5+
6+
@Entity()
7+
export class Rating {
8+
@PrimaryGeneratedColumn()
9+
public readonly id!: number;
10+
@OneToOne(() => User, { eager: true })
11+
public user!: User;
12+
@OneToOne(() => Project, { eager: true })
13+
public project!: Project;
14+
@OneToOne(() => Criteria, { eager: true })
15+
public critera!: Criteria;
16+
@Column()
17+
// 1 - 5
18+
public rating!: number;
19+
}
20+
21+
// TODO mvp: only create ratings, no update and delete

backend/src/entities/team.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
2-
3-
function Longtext() {
4-
// Sqlite doesn't support longtext. I hate this, but it is what it is if we want
5-
// to keep backend tests and prepare tilt for the upcoming Hackaburg as quickly
6-
// as possible.
7-
if (process.env.NODE_ENV === "test") {
8-
return Column("text");
9-
}
10-
return Column("longtext");
11-
}
2+
import { Longtext } from "./longtext";
123

134
@Entity()
145
export class Team {

quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
```sh
44
# prep
55
cp backend/.env.example backend/.env
6-
docker run --name backend --network host -v $(pwd):/app -w /app node:alpine yarn
6+
docker run --name backend --network host -v $(pwd):/app -w /app node:alpine yarn install
77

88
# start everything
99
docker compose up db phpmyadmin maildev

0 commit comments

Comments
 (0)