Skip to content

Commit f57c469

Browse files
committed
chore: fix group issue
1 parent 8c000d9 commit f57c469

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

platforms/evoting-api/src/services/VoteService.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {

platforms/evoting-api/src/services/poll.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ export class PollService {
159159
}
160160

161161
const vote = this.voteRepository.create({
162-
poll,
163-
voterId: user.id,
162+
pollId,
163+
userId: user.id,
164+
voterId: user.ename, // Use ename for consistency with other vote creation methods
164165
data,
165166
});
166167

0 commit comments

Comments
 (0)