Skip to content

Commit

Permalink
add: achivemets to profile (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
automerge-pingpong[bot] committed Nov 6, 2023
2 parents dc9e1d1 + 666eef3 commit cb2a645
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 295 deletions.
540 changes: 276 additions & 264 deletions backend/code/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"figlet": "^1.7.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"prisma-dbml-generator": "^0.10.0",
"prisma-dbml-generator": "^0.9.1",
"prompt": "^1.3.0",
"prompt-sync": "^4.2.0",
"source-map-support": "^0.5.21",
Expand Down
8 changes: 4 additions & 4 deletions backend/code/src/game/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export class GameService {
score2: true,
participant1: {
select: {
userId:true,
userId: true,
Username: true,
avatar: true,
},
},
participant2: {
select: {
userId:true,
userId: true,
Username: true,
avatar: true,
},
Expand All @@ -85,13 +85,13 @@ export class GameService {
match: {
createdAt: match.createdAt,
Player1: {
id:match.participant1.userId,
id: match.participant1.userId,
username: match.participant1.Username,
score: match.score1,
avatar: avatar1,
},
Player2: {
id:match.participant2.userId,
id: match.participant2.userId,
username: match.participant2.Username,
score: match.score2,
avatar: avatar2,
Expand Down
6 changes: 4 additions & 2 deletions backend/code/src/gateways/gateways.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class Gateways implements OnGatewayConnection, OnGatewayDisconnect {

const friendIds = frienduserIds
.map((friend) => (friend.toId === userId ? friend.fromId : friend.toId))
.filter((id) => this.server.sockets.adapter.rooms.get(`User:${id}`)?.size);
.filter(
(id) => this.server.sockets.adapter.rooms.get(`User:${id}`)?.size,
);

client.emit('onlineFriends', friendIds);

Expand All @@ -93,7 +95,7 @@ export class Gateways implements OnGatewayConnection, OnGatewayDisconnect {

@OnEvent('sendMessages')
sendMessage(message: MessageFormatDto) {
console.log("recive msg !")
console.log('recive msg !');
const chanellname: string = `Romm:${message.roomId}`;
this.server.to(chanellname).emit('message', message);
}
Expand Down
11 changes: 5 additions & 6 deletions backend/code/src/leaderboard/leaderboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class LeaderBoardService {
},
},
});
const leaderboardsPromises = leaderboard.map(async (user ) => {
const lead = await this.prisma.user.findUnique({
const leaderboardsPromises = leaderboard.map(async (user) => {
const lead = await this.prisma.user.findUnique({
where: {
userId: user.winner_id,
},
Expand All @@ -28,12 +28,11 @@ export class LeaderBoardService {
avatar: true,
userId: true,
},
},
)
});
return {
...lead,
wins: user._count.id
}
wins: user._count.id,
};
});
return await Promise.all(leaderboardsPromises);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ async function bootstrap() {
.addTag('friends')
.addTag('rooms')
.addTag('Messages')
.addTag('user')
.addTag('game')
.addTag('user')
.addTag('game')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
Expand Down
2 changes: 1 addition & 1 deletion backend/code/src/messages/dto/message-format.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MessageFormatDto {
this.roomId = messageData.roomId;
this.authorId = messageData.authorId;
this.Username = messageData.author.Username;

this.avatar = {
thumbnail: `https://res.cloudinary.com/trandandan/image/upload/c_thumb,h_48,w_48/${messageData.author.avatar}`,
medium: `https://res.cloudinary.com/trandandan/image/upload/c_thumb,h_72,w_72/${messageData.author.avatar}`,
Expand Down
3 changes: 1 addition & 2 deletions backend/code/src/messages/messages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ export class MessagesService {
content: messageDto.content,
roomId: channelId,
authorId: userId,

},
include: {
author: {
select: {
avatar: true,
Username:true,
Username: true,
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions backend/code/src/profile/dto/profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ProfileDtoProps = Partial<User> &
right_friends: Friend[];
roomMember: RoomMember[];
owned_rooms: Room[];
achievement: number;
}>;

export type NAME = {
Expand Down Expand Up @@ -41,6 +42,7 @@ export class ProfileDto {
if (is_friend) {
this.friendship = [...userData.left_friends, ...userData.right_friends];
}
this.achievement = userData.achievement;
}

@ApiProperty({ example: 'cln8xxhut0000stofeef' })
Expand Down Expand Up @@ -73,4 +75,7 @@ export class ProfileDto {
username: string;

friendship: Friend[];

@ApiProperty({ example: 1, required: false })
achievement: number;
}
2 changes: 1 addition & 1 deletion backend/code/src/profile/profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { QueryOffsetDto } from 'src/friends/dto/query-ofsset-dto';
@ApiCookieAuth('X-Acces-Token')
@Controller('profile')
export class ProfileController {
constructor(private readonly profileService: ProfileService) { }
constructor(private readonly profileService: ProfileService) {}

@Get('me')
@ApiOkResponse({ type: ProfileDto })
Expand Down
30 changes: 28 additions & 2 deletions backend/code/src/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ export class ProfileService {
if (!user) {
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
}
return new ProfileDto(user, false);
const wonMatches = await this.prisma.match.count({
where: {
winner_id: userId,
},
});

const achievement =
wonMatches === 0
? null
: wonMatches >= 100
? 2
: Math.floor(Math.log10(wonMatches));

return new ProfileDto({ ...user, achievement }, false);
}

async getFriendProfile(
Expand All @@ -34,7 +47,20 @@ export class ProfileService {
if (!user) {
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
}
return new ProfileDto(user, true);

const wonMatches = await this.prisma.match.count({
where: {
winner_id: friendId,
},
});

const achievement =
wonMatches === 0
? null
: wonMatches >= 100
? 2
: Math.floor(Math.log10(wonMatches));
return new ProfileDto({ ...user, achievement }, true);
}

async updateProfile(
Expand Down
18 changes: 9 additions & 9 deletions backend/code/src/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ export class RoomsController {
return this.roomsService.listRooms(userId, offset, limit, joined);
}

@Get('dms')
@HttpCode(HttpStatus.OK)
@UseGuards(AtGuard)
async getDMs(
@GetCurrentUser('userId') userId: string,
@Query() { offset, limit }: QueryOffsetDto,
) {
return this.roomsService.getDMs(userId, offset, limit);
}
@Get('dms')
@HttpCode(HttpStatus.OK)
@UseGuards(AtGuard)
async getDMs(
@GetCurrentUser('userId') userId: string,
@Query() { offset, limit }: QueryOffsetDto,
) {
return this.roomsService.getDMs(userId, offset, limit);
}
}
4 changes: 3 additions & 1 deletion backend/code/src/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ export class RoomsService {
is_mueted: true,
},
});
const filtredmembers = members.filter((member) => !member.is_banned || user.is_admin)
const filtredmembers = members.filter(
(member) => !member.is_banned || user.is_admin,
);
return filtredmembers.map((member) => {
if (!member.is_banned || user.is_admin) {
const avatar: PICTURE = {
Expand Down

0 comments on commit cb2a645

Please sign in to comment.