@@ -66,10 +66,16 @@ export class VoteService {
66
66
typedData = { mode : "rank" , data : convertedData } ;
67
67
}
68
68
69
+ // Get the user to get their ename for voterId
70
+ const user = await this . userRepository . findOne ( { where : { id : userId } } ) ;
71
+ if ( ! user ) {
72
+ throw new Error ( 'User not found' ) ;
73
+ }
74
+
69
75
const vote = this . voteRepository . create ( {
70
76
pollId,
71
77
userId,
72
- voterId : userId , // For non-blind voting, voterId is the same as userId
78
+ voterId : user . ename , // Use the user's ename as voterId for consistency with blind voting
73
79
data : typedData
74
80
} ) ;
75
81
@@ -84,9 +90,24 @@ export class VoteService {
84
90
}
85
91
86
92
async getUserVote ( pollId : string , userId : string ) : Promise < Vote | null > {
87
- return await this . voteRepository . findOne ( {
93
+ // First try to find by userId (for normal votes)
94
+ let vote = await this . voteRepository . findOne ( {
88
95
where : { pollId, userId }
89
96
} ) ;
97
+
98
+ // If no vote found by userId, check if this is a blind vote
99
+ // For blind votes, we need to get the user's ename and check voterId
100
+ if ( ! vote ) {
101
+ const user = await this . userRepository . findOne ( { where : { id : userId } } ) ;
102
+ if ( user ) {
103
+ // Check for blind vote by voterId (ename)
104
+ vote = await this . voteRepository . findOne ( {
105
+ where : { pollId, voterId : user . ename }
106
+ } ) ;
107
+ }
108
+ }
109
+
110
+ return vote ;
90
111
}
91
112
92
113
async getPollResults ( pollId : string ) : Promise < any > {
0 commit comments