Skip to content

Commit

Permalink
Merge branch 'development' into feature/MB/469/mobile-user-profile-page
Browse files Browse the repository at this point in the history
  • Loading branch information
senaal committed Nov 26, 2023
2 parents 0408ded + dfa6f63 commit b753df7
Show file tree
Hide file tree
Showing 39 changed files with 3,437 additions and 600 deletions.
10 changes: 8 additions & 2 deletions ludos/backend/src/controllers/review.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export class ReviewController {
@Req() req: AuthorizedRequest,
@Param('reviewId') reviewId: string,
) {
const review = await this.reviewService.getReviewById(req.user.id, reviewId);
const review = await this.reviewService.getReviewById(
req.user.id,
reviewId,
);
return review;
}

Expand All @@ -129,7 +132,10 @@ export class ReviewController {
@Req() req: AuthorizedRequest,
@Param('gameId') gameId: string,
) {
const reviews = await this.reviewService.getReviewsByGameId(req.user.id, gameId);
const reviews = await this.reviewService.getReviewsByGameId(
req.user.id,
gameId,
);
return reviews;
}
}
1 change: 0 additions & 1 deletion ludos/backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export class UserController {
public async getUserInfoById(@Req() req: AuthorizedRequest) {
return await this.userService.getUserInfo(req.user.id);
}

@HttpCode(200)
@ApiUnauthorizedResponse({
description: 'Invalid User',
Expand Down
4 changes: 2 additions & 2 deletions ludos/backend/src/dtos/post/response/get.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PostGetResponseDto {
tags: string[];

@Expose()
@ApiProperty({type: () => UserInOtherResponsesDto})
@ApiProperty({ type: () => UserInOtherResponsesDto })
@Type(() => UserInOtherResponsesDto)
likedUsers: UserInOtherResponsesDto;

Expand All @@ -42,7 +42,7 @@ export class PostGetResponseDto {
numberOfLikes: number;

@Expose()
@ApiProperty({type: () => UserInOtherResponsesDto})
@ApiProperty({ type: () => UserInOtherResponsesDto })
@Type(() => UserInOtherResponsesDto)
dislikedUsers: UserInOtherResponsesDto;

Expand Down
6 changes: 6 additions & 0 deletions ludos/backend/src/dtos/review/response/getInfo.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export class ReviewGetInfoResponseDto {

@ApiProperty()
isBelongToUser: boolean;

@ApiProperty()
isLikedByUser: boolean;

@ApiProperty()
isDislikedByUser: boolean;
}
57 changes: 27 additions & 30 deletions ludos/backend/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import * as bcrypt from 'bcrypt';
import {
Entity,
Column,
PrimaryGeneratedColumn,
BeforeInsert,
BeforeUpdate,
OneToMany,
Column,
Entity,
Index,
ManyToMany,
VirtualColumn
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import * as bcrypt from 'bcrypt';
import { Game } from './game.entity';
import { UserType } from '../enums/user-type.enum';
import { Review } from './review.entity';
import { Game } from './game.entity';
import { Post } from './post.entity';
import { Rating } from './rating.entity';
import { Review } from './review.entity';

@Entity('users')
export class User {
Expand All @@ -34,11 +33,10 @@ export class User {
@ManyToMany(() => Game, (game) => game.followerList)
followedGames: Game[];

@VirtualColumn({
query: (alias) => `SELECT COUNT(*) FROM game_user_follows WHERE "usersId" = ${alias}.id `,
})
numberOfFollowedGames: number;

// @VirtualColumn({
// query: (alias) => `SELECT COUNT(*) FROM game_user_follows WHERE "usersId" = ${alias}.id `,
// })
// numberOfFollowedGames: number;

@Column({ default: false })
isNotificationEnabled: boolean;
Expand All @@ -61,32 +59,31 @@ export class User {
@OneToMany('Review', 'user')
reviews: Review[];

@VirtualColumn({
query: (alias) => `SELECT COUNT(*) FROM reviews WHERE "userId" = ${alias}.id `,
})
numberOfReviews: number;
// @VirtualColumn({
// query: (alias) => `SELECT COUNT(*) FROM reviews WHERE "userId" = ${alias}.id `,
// })
// numberOfReviews: number;

@OneToMany('Post', 'user')
posts: Post[];

@VirtualColumn({
query: (alias) => `SELECT COUNT(*) FROM posts WHERE "userId" = ${alias}.id `,
})
numberOfPosts: number;

// @VirtualColumn({
// query: (alias) => `SELECT COUNT(*) FROM posts WHERE "userId" = ${alias}.id `,
// })
// numberOfPosts: number;

@VirtualColumn({
query: (alias) => `SELECT COUNT(*) FROM comments WHERE "authorId" = ${alias}.id `,
})
numberOfComments: number;
// @VirtualColumn({
// query: (alias) => `SELECT COUNT(*) FROM comments WHERE "authorId" = ${alias}.id `,
// })
// numberOfComments: number;

@OneToMany('Rating', 'user')
ratingList: Rating[];

@VirtualColumn({
query: (alias) => `SELECT COUNT(*) FROM ratings WHERE "userId" = ${alias}.id `,
})
numberOfRatings: number;
// @VirtualColumn({
// query: (alias) => `SELECT COUNT(*) FROM ratings WHERE "userId" = ${alias}.id `,
// })
// numberOfRatings: number;

@ManyToMany('Review', 'likedUsers')
likedReviews: Review[];
Expand Down
2 changes: 1 addition & 1 deletion ludos/backend/src/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class GameService {
const updated = Object.assign(game, gameEditDto);
await this.gameRepository.save(updated);
}

async addCompletionDuration(
userId: string,
gameId: string,
Expand Down
21 changes: 13 additions & 8 deletions ludos/backend/src/services/review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ export class ReviewService {
}

const loggedUser = await this.userRepository.findUserById(userId);
if (!loggedUser) {
throw new NotFoundException('User Not Found!');
}
if (!loggedUser) {
throw new NotFoundException('User Not Found!');
}

const likedUserCount = review.likedUsers.length;
const dislikedUserCount = review.dislikedUsers.length;

return {
reviewId: review.id,
content: review.content,
Expand All @@ -247,7 +248,9 @@ export class ReviewService {
gameId: review.game.id,
likedUserCount: likedUserCount,
dislikedUserCount: dislikedUserCount,
isBelongToUser: review.user.id == loggedUser.id
isBelongToUser: review.user.id == loggedUser.id,
isLikedByUser: review.likedUsers.some(user => user.id === userId),
isDislikedByUser: review.dislikedUsers.some(user => user.id === userId)
};
}

Expand All @@ -261,9 +264,9 @@ export class ReviewService {
}

const loggedUser = await this.userRepository.findUserById(userId);
if (!loggedUser) {
throw new NotFoundException('User Not Found!');
}
if (!loggedUser) {
throw new NotFoundException('User Not Found!');
}

const reviews = await this.reviewRepository.findReviewsByGame(game);

Expand All @@ -276,7 +279,9 @@ export class ReviewService {
gameId: review.game.id,
likedUserCount: review.likedUsers.length,
dislikedUserCount: review.dislikedUsers.length,
isBelongToUser: review.user.id == loggedUser.id
isBelongToUser: review.user.id == loggedUser.id,
isLikedByUser: review.likedUsers.some(user => user.id === userId),
isDislikedByUser: review.dislikedUsers.some(user => user.id === userId)
}));
return mappedReviews;
}
Expand Down
8 changes: 4 additions & 4 deletions ludos/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
],
"max-len": [
2,
120,
1000,
{
ignoreStrings: true,
ignoreTemplateLiterals: true,
Expand All @@ -49,10 +49,10 @@ module.exports = {
children: "never",
},
],
"space-infix-ops": ["error", { int32Hint: false }],
"import/first": ["error"],
"space-infix-ops": ["warn", { int32Hint: false }],
"import/first": ["warn"],
indent: ["warn", 2, { SwitchCase: 1, ObjectExpression: 1 }],
"object-property-newline": ["warn", { allowAllPropertiesOnSameLine: true }],
"no-multi-spaces": ["error", { ignoreEOLComments: true }],
"no-multi-spaces": ["warn", { ignoreEOLComments: true }],
},
};
60 changes: 60 additions & 0 deletions ludos/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ludos/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"react-icons": "^4.11.0",
"react-router-dom": "^6.17.0",
"react-scripts": "5.0.1",
"react-slick": "^0.29.0",
"react-toastify": "^9.1.3",
"slick-carousel": "^1.8.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down

0 comments on commit b753df7

Please sign in to comment.