File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -145,15 +145,22 @@ export class UserService {
145145 if ( ! user ) {
146146 throw new Error ( 'User not found' ) ;
147147 }
148-
149148 const poll = await this . databaseService . poll . findUnique ( {
150149 where : { pollId : dto . pollId } ,
151150 select : { endDate : true , options : true } ,
152151 } ) ;
153152 if ( ! poll || poll . endDate < new Date ( ) ) {
154153 throw new Error ( 'Poll is not active or does not exist' ) ;
155154 }
156-
155+ const existingVote = await this . databaseService . vote . findFirst ( {
156+ where : {
157+ pollId : dto . pollId ,
158+ userId : user . id ,
159+ } ,
160+ } ) ;
161+ if ( existingVote ) {
162+ throw new Error ( 'User has already voted in this poll' ) ;
163+ }
157164 const vote = await this . databaseService . vote . create ( {
158165 data : {
159166 userId : user . id ,
You can’t perform that action at this time.
0 commit comments