File tree Expand file tree Collapse file tree 1 file changed +21
-9
lines changed
Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -102,19 +102,31 @@ export class PollService {
102102 throw new Error ( 'worldId Not Provided' ) ;
103103 }
104104
105- if ( userCreated ) {
106- filters . authorUserId = userId ;
107- }
108-
109- // Get polls user voted in
110- let votedPollIds : number [ ] = [ ] ;
111- if ( userVoted ) {
105+ if ( userCreated && userVoted ) {
106+ // Get polls user voted in
112107 const userVotes = await this . databaseService . vote . findMany ( {
113108 where : { userId } ,
114109 select : { pollId : true } ,
115110 } ) ;
116- votedPollIds = userVotes . map ( ( v ) => v . pollId ) ;
117- filters . pollId = { in : votedPollIds } ;
111+ const votedPollIds = userVotes . map ( ( v ) => v . pollId ) ;
112+
113+ // Use OR condition to get polls where user voted OR user created
114+ filters . OR = [ { authorUserId : userId } , { pollId : { in : votedPollIds } } ] ;
115+ } else {
116+ if ( userCreated ) {
117+ filters . authorUserId = userId ;
118+ }
119+
120+ // Get polls user voted in
121+ let votedPollIds : number [ ] = [ ] ;
122+ if ( userVoted ) {
123+ const userVotes = await this . databaseService . vote . findMany ( {
124+ where : { userId } ,
125+ select : { pollId : true } ,
126+ } ) ;
127+ votedPollIds = userVotes . map ( ( v ) => v . pollId ) ;
128+ filters . pollId = { in : votedPollIds } ;
129+ }
118130 }
119131
120132 // Sorting options
You can’t perform that action at this time.
0 commit comments