Skip to content

Commit

Permalink
Merge pull request #675 from bounswe/be-620/Add_user_info_to_ranking
Browse files Browse the repository at this point in the history
be-620: Add current user information to ranking
  • Loading branch information
BatuhanIlhan authored Dec 23, 2023
2 parents 4f75329 + ed52e31 commit 51e8651
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
11 changes: 7 additions & 4 deletions app/backend/src/ranking/ranking.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { RankingService } from './ranking.service';
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { IsUUID } from 'class-validator';
import { AuthGuard } from '../auth/guards/auth.guard';
import { VerificationGuard } from '../auth/guards/verification.guard';

@ApiBearerAuth()
@Controller('ranking')
@ApiTags('ranking')

export class RankingController {
constructor(private readonly rankingService: RankingService) {}

@UseGuards(AuthGuard, VerificationGuard)
@Get(':name')
@ApiResponse({ status: 200, description: 'Ranking is fetched successfully.' })
@ApiResponse({ status: 404, description: 'Ranking is not found.' })
@ApiResponse({
status: 500,
description: 'Internal server error, contact with backend team.',
})
findAll(@Param("name") name : string) {
return this.rankingService.findAll(name);
findAll(@Param("name") name : string, @Req() request: any) {
return this.rankingService.findAll(name,request.user.id);
}


Expand Down
7 changes: 5 additions & 2 deletions app/backend/src/ranking/ranking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import { Option } from '../option/entities/option.entity';
import { OptionService } from '../option/option.service';
import { Poll } from '../poll/entities/poll.entity';
import { Tag } from '../tag/entities/tag.entity';
import { Report } from '../user/entities/report.entity';
import { UserService } from '../user/user.service';
import { BadgeService } from '../badge/badge.service';

@Module({
imports: [
TypeOrmModule.forFeature([Ranking,Vote,
Option,
User,
Badge,Poll,Tag])
Badge,Poll,Tag,Report])
],
controllers: [RankingController],
providers: [RankingService,VoteService,OptionService],
providers: [RankingService,VoteService,OptionService,UserService,BadgeService],
})
export class RankingModule {}
19 changes: 15 additions & 4 deletions app/backend/src/ranking/ranking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ export class RankingService {
){}


async findAll(id:string) {
return await this.rankingRepository.find(
async findAll(tagID:string, userID:string) {
const currenUser = await this.rankingRepository.findOne({
where:{
tag:{id:tagID},
user: {id:userID}
},
relations:["user","tag"]
})

const ranking= await this.rankingRepository.find(
{
where:
{tag:{
id:id,
id:tagID,
}
},
order:{
Expand All @@ -33,6 +41,9 @@ export class RankingService {
relations:["user","tag"]
}
)
const response = {"ranking": ranking, "currenUser": currenUser}

return response;
}


Expand All @@ -47,7 +58,7 @@ export class RankingService {
}
)
const userIds: string[] = votes.map((vote) => vote.user.id);
poll.tags.push(await this.tagRepository.findOne({where:{name:"general"}}));
poll.tags.push(await this.tagRepository.findOne({where: {name: "general"}}));

poll.tags.forEach( async (tag) => {this.updateScoreByTag(tag.id,userIds)});

Expand Down

0 comments on commit 51e8651

Please sign in to comment.