Skip to content

Commit

Permalink
Merge pull request #672 from bounswe/be-619/Add_global_tag
Browse files Browse the repository at this point in the history
be-619/Add general tag rankings
  • Loading branch information
BatuhanIlhan authored Dec 23, 2023
2 parents b127095 + 35ce9cc commit 72405e9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
15 changes: 11 additions & 4 deletions app/backend/src/ranking/ranking.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { RankingService } from './ranking.service';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { IsUUID } from 'class-validator';

@ApiBearerAuth()
@Controller('ranking')
@ApiTags('ranking')
export class RankingController {
constructor(private readonly rankingService: RankingService) {}

@Get(':id')
findAll(@Param("id") id : string) {
return this.rankingService.findAll(id);
@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);
}


Expand Down
3 changes: 2 additions & 1 deletion app/backend/src/ranking/ranking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { Badge } from '../badge/entities/badge.entity';
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';

@Module({
imports: [
TypeOrmModule.forFeature([Ranking,Vote,
Option,
User,
Badge,Poll])
Badge,Poll,Tag])
],
controllers: [RankingController],
providers: [RankingService,VoteService,OptionService],
Expand Down
14 changes: 5 additions & 9 deletions app/backend/src/ranking/ranking.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Injectable } from '@nestjs/common';
import { CreateRankingDto } from './dto/create-ranking.dto';
import { UpdateRankingDto } from './dto/update-ranking.dto';
import { Poll } from '../poll/entities/poll.entity';
import { Option } from '../option/entities/option.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Ranking } from './entities/ranking.entity';
import { Repository } from 'typeorm';
import { User } from '../user/entities/user.entity';
import { Vote } from '../vote/entities/vote.entity';
import { Tag } from '../tag/entities/tag.entity';

@Injectable()
export class RankingService {
Expand All @@ -16,11 +14,8 @@ export class RankingService {
private readonly rankingRepository: Repository<Ranking>,
@InjectRepository(Vote)
private readonly voteRepository: Repository<Vote>,
@InjectRepository(User)
private readonly userRepository: Repository<User>,
@InjectRepository(Poll)
private readonly pollRepository: Repository<Poll>,

@InjectRepository(Tag)
private readonly tagRepository: Repository<Tag>,
){}


Expand All @@ -46,12 +41,13 @@ export class RankingService {
relations:["user"],
where:{
option:{
id:"334483e2-4b39-4c10-896d-47cb1ba1c1e9"
id:option.id
}
}
}
)
const userIds: string[] = votes.map((vote) => vote.user.id);
poll.tags.push(await this.tagRepository.findOne({where:{name:"general"}}));

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

Expand Down
2 changes: 1 addition & 1 deletion app/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class UserService {
'isBanned',
'rankings',
],
});
})};

public async searchUsernames(query: string): Promise<User[]> {
return this.userRepository
Expand Down

0 comments on commit 72405e9

Please sign in to comment.