Skip to content

Commit 7776a35

Browse files
committed
fix: add poll and vote entities
1 parent 9edc741 commit 7776a35

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

platforms/eVoting/src/app/(app)/create/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ export default function CreatePoll() {
322322
<div className="mt-2 space-y-3">
323323
{options.map((option, index) => (
324324
<div
325+
// biome-ignore lint/suspicious/noArrayIndexKey: jatt dont care OOOOOOOOOO
325326
key={index}
326327
className="flex items-center space-x-2"
327328
>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {
2+
Column,
3+
CreateDateColumn,
4+
Entity,
5+
OneToMany,
6+
PrimaryGeneratedColumn,
7+
UpdateDateColumn,
8+
} from "typeorm";
9+
import { Vote } from "./Vote";
10+
11+
@Entity("poll")
12+
export class Poll {
13+
@PrimaryGeneratedColumn("uuid")
14+
id: string;
15+
16+
@Column("varchar", { length: 255 })
17+
title: string;
18+
19+
@Column("enum", {
20+
enum: ["normal", "point", "rank"],
21+
default: "normal",
22+
})
23+
mode: "normal" | "point" | "rank";
24+
25+
@Column("enum", {
26+
enum: ["public", "private"],
27+
default: "public",
28+
})
29+
visibility: "public" | "private";
30+
31+
@Column("simple-array")
32+
options: string[]; // stored as comma-separated values
33+
34+
@Column({ type: "timestamp", nullable: true })
35+
deadline: Date | null;
36+
37+
@OneToMany(
38+
() => Vote,
39+
(vote) => vote.poll,
40+
)
41+
votes: Vote[];
42+
43+
@CreateDateColumn()
44+
createdAt: Date;
45+
46+
@UpdateDateColumn()
47+
updatedAt: Date;
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
Column,
3+
CreateDateColumn,
4+
Entity,
5+
JoinColumn,
6+
ManyToOne,
7+
PrimaryGeneratedColumn,
8+
UpdateDateColumn,
9+
} from "typeorm";
10+
import { Poll } from "./Poll";
11+
12+
@Entity("vote")
13+
export class Vote {
14+
@PrimaryGeneratedColumn("uuid")
15+
id: string;
16+
17+
@ManyToOne(
18+
() => Poll,
19+
(poll) => poll.votes,
20+
{ onDelete: "CASCADE" },
21+
)
22+
@JoinColumn({ name: "pollId" })
23+
poll: Poll;
24+
25+
@Column("uuid")
26+
pollId: string;
27+
28+
// This can be user ID, session ID, or anonymous identifier
29+
@Column("varchar", { length: 255 })
30+
voterId: string;
31+
32+
/**
33+
* For "normal" mode: array of chosen options (usually 1)
34+
* For "point" mode: { option: string, points: number }[]
35+
* For "rank" mode: ordered array of option strings
36+
*
37+
* Stored as JSON for flexibility
38+
*/
39+
@Column("jsonb")
40+
data:
41+
| string[] // normal
42+
| { option: string; points: number }[] // point
43+
| string[]; // rank
44+
45+
@CreateDateColumn()
46+
createdAt: Date;
47+
48+
@UpdateDateColumn()
49+
updatedAt: Date;
50+
}

0 commit comments

Comments
 (0)