Skip to content

Commit 5d36e56

Browse files
committed
feat: Add feature to describe participant after session creation
1 parent 22656fe commit 5d36e56

File tree

6 files changed

+248
-93
lines changed

6 files changed

+248
-93
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE participants_migration (
2+
id INTEGER PRIMARY KEY AUTOINCREMENT,
3+
session_id INTEGER NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
4+
name TEXT NOT NULL,
5+
description TEXT,
6+
role_weight DECIMAL(1, 2) NOT NULL DEFAULT 1,
7+
currency_weight DECIMAL(1, 2) NOT NULL DEFAULT 1
8+
);
9+
10+
INSERT INTO participants_migration (id, session_id, name, description, role_weight, currency_weight)
11+
SELECT id, session_id, name, description, role_weight, currency_weight
12+
FROM participants;
13+
14+
DROP TABLE participants;
15+
16+
ALTER TABLE participants_migration RENAME TO participants;

src/lib/database.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ export class DatabaseService {
3030
const participantStatements = session.participants.map((participant) =>
3131
this.db
3232
.prepare(
33-
'INSERT INTO participants (session_id, name, description, role_weight, currency_weight) VALUES (?, ?, ?, ?, ?)'
33+
'INSERT INTO participants (session_id, name, role_weight, currency_weight) VALUES (?, ?, ?, ?)'
3434
)
3535
.bind(
3636
result.id,
3737
participant.name,
38-
participant.description,
3938
participant.roleWeight,
4039
participant.currencyWeight
4140
)
@@ -102,6 +101,22 @@ export class DatabaseService {
102101
return count > 0;
103102
}
104103

104+
async setParticipantDescription(
105+
participantId: number,
106+
description: string
107+
): Promise<boolean> {
108+
try {
109+
const { success } = await this.db
110+
.prepare('UPDATE participants SET description = ? WHERE id = ?')
111+
.bind(description, participantId)
112+
.run();
113+
return success;
114+
} catch (error) {
115+
console.error('Error updating participant description:', error);
116+
return false;
117+
}
118+
}
119+
105120
async deleteSession(sessionKey: string): Promise<boolean> {
106121
try {
107122
const { success } = await this.db

src/lib/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export interface CreateSessionRequest {
2020
stake: number;
2121
participants: Array<{
2222
name: string;
23-
description: string;
2423
roleWeight: number;
2524
currencyWeight: number;
2625
}>;
@@ -35,6 +34,11 @@ export interface SubmitVoteRequest {
3534
}>;
3635
}
3736

37+
export interface PatchDescriptionRequest {
38+
participantId: number;
39+
description: string;
40+
}
41+
3842
export interface SessionResponse {
3943
topic: string;
4044
description: string;

0 commit comments

Comments
 (0)