Browse Source

Add database entities for contest feature

ghorsington 5 years ago
parent
commit
fd341968ad
3 changed files with 62 additions and 0 deletions
  1. 28 0
      db/src/entity/Contest.ts
  2. 16 0
      db/src/entity/ContestEntry.ts
  3. 18 0
      db/src/entity/ContestVote.ts

+ 28 - 0
db/src/entity/Contest.ts

@@ -0,0 +1,28 @@
+import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
+import { ContestEntry } from "./ContestEntry";
+import { ContestVote } from "./ContestVote";
+
+@Entity()
+export class Contest {
+
+    @PrimaryGeneratedColumn()
+    id: number;
+
+    @Column()
+    startDate: Date;
+
+    @Column()
+    endDate: Date;
+
+    @Column()
+    channel: string;
+
+    @Column()
+    announceWinners: boolean;
+
+    @OneToMany(type => ContestEntry, entry => entry.contest)
+    entries: ContestEntry[];
+
+    @OneToMany(type => ContestVote, vote => vote.contest)
+    votes: ContestVote[];
+}

+ 16 - 0
db/src/entity/ContestEntry.ts

@@ -0,0 +1,16 @@
+import {Entity, PrimaryColumn, Column, ManyToOne, JoinColumn} from "typeorm";
+import {Contest} from "./Contest";
+import { ContestVote } from "./ContestVote";
+
+@Entity()
+export class ContestEntry {
+
+    @PrimaryColumn()
+    msgId: string;
+
+    @ManyToOne(type => Contest, contest => contest.entries)
+    contest: Contest;
+
+    @ManyToOne(type => ContestVote, vote => vote.contest)
+    votes: ContestVote[];
+}

+ 18 - 0
db/src/entity/ContestVote.ts

@@ -0,0 +1,18 @@
+import { Contest } from "./Contest";
+import { ContestEntry } from "./ContestEntry";
+import { Entity, PrimaryColumn, ManyToOne } from "typeorm";
+
+@Entity()
+export class ContestVote {
+
+    @PrimaryColumn()
+    userId: string;
+
+    // :thonq
+    @PrimaryColumn()
+    @ManyToOne(type => Contest, contest => contest.votes)
+    contest: Contest;
+
+    @ManyToOne(type => ContestEntry, entry => entry.votes)
+    contestEntry: ContestEntry;
+}