Skip to content

Commit efba03e

Browse files
authored
Merge pull request #53 from GeneralMagicio/fixes-on-getUserData
Fixes on get user data
2 parents 93b2c5e + dabc453 commit efba03e

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/user/user.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class UserDataResponseDto {
66
pollsCreated: number;
77
pollsParticipated: number;
88
worldID: string;
9+
worldProfilePic?: string | null;
910
}
1011

1112
export class GetUserActivitiesDto {

src/user/user.service.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,28 @@ export class UserService {
3535
async getUserData(dto: GetUserDataDto): Promise<UserDataResponseDto> {
3636
const user = await this.databaseService.user.findUnique({
3737
where: { worldID: dto.worldID },
38-
select: {
39-
pollsCreatedCount: true,
40-
pollsParticipatedCount: true,
41-
worldID: true,
42-
},
38+
select: { id: true, worldID: true },
4339
});
4440
if (!user) {
4541
throw new Error('User not found');
4642
}
43+
const pollsCreated = await this.databaseService.userAction.count({
44+
where: {
45+
userId: user.id,
46+
type: ActionType.CREATED,
47+
},
48+
});
49+
const pollsParticipated = await this.databaseService.userAction.count({
50+
where: {
51+
userId: user.id,
52+
type: ActionType.VOTED,
53+
},
54+
});
4755
return {
48-
pollsCreated: user.pollsCreatedCount,
49-
pollsParticipated: user.pollsParticipatedCount,
56+
pollsCreated,
57+
pollsParticipated,
5058
worldID: user.worldID,
59+
worldProfilePic: null,
5160
};
5261
}
5362

0 commit comments

Comments
 (0)