@@ -66,10 +66,16 @@ export class VoteService {
6666 typedData = { mode : "rank" , data : convertedData } ;
6767 }
6868
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+
6975 const vote = this . voteRepository . create ( {
7076 pollId,
7177 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
7379 data : typedData
7480 } ) ;
7581
@@ -84,9 +90,24 @@ export class VoteService {
8490 }
8591
8692 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 ( {
8895 where : { pollId, userId }
8996 } ) ;
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 ;
90111 }
91112
92113 async getPollResults ( pollId : string ) : Promise < any > {
0 commit comments