@@ -96,24 +96,35 @@ export class UserService {
9696 title : true ,
9797 description : true ,
9898 endDate : true ,
99- participantCount : true ,
10099 authorUserId : true ,
101100 } ,
102101 } ,
103102 } ,
104103 } ) ;
105- const actions : UserActionDto [ ] = userActions . map ( ( action ) => ( {
106- id : action . id ,
107- type : action . type . toLowerCase ( ) as 'created' | 'voted' ,
108- pollId : action . poll . pollId ,
109- pollTitle : action . poll . title ,
110- pollDescription : action . poll . description ?? '' ,
111- endDate : action . poll . endDate ,
112- isActive : action . poll . endDate >= now ,
113- votersParticipated : action . poll . participantCount ,
114- authorUserId : action . poll . authorUserId ,
115- createdAt : action . createdAt ,
116- } ) ) ;
104+ const actions : UserActionDto [ ] = await Promise . all (
105+ // TODO: it's a temporary work around, should add count to Poll and User and authorWorldId to UserAction later
106+ userActions . map ( async ( action ) => {
107+ const participantCount = await this . databaseService . userAction . count ( {
108+ where : { pollId : action . poll . pollId , type : ActionType . VOTED } ,
109+ } ) ;
110+ const authorWorldId = await this . databaseService . user . findUnique ( {
111+ where : { id : action . poll . authorUserId } ,
112+ select : { worldID : true } ,
113+ } ) ;
114+ return {
115+ id : action . id ,
116+ type : action . type ,
117+ pollId : action . poll . pollId ,
118+ pollTitle : action . poll . title ,
119+ pollDescription : action . poll . description ?? '' ,
120+ endDate : action . poll . endDate ,
121+ isActive : action . poll . endDate >= now ,
122+ votersParticipated : participantCount ,
123+ authorWorldId : authorWorldId ?. worldID || '' ,
124+ createdAt : action . createdAt ,
125+ } ;
126+ } ) ,
127+ ) ;
117128 return { userActions : actions } ;
118129 }
119130
0 commit comments