You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
2 years ago
|
import { Controller, Get, Param, Post, Req, UseGuards } from '@nestjs/common';
|
||
|
import { Request } from 'express';
|
||
|
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
|
||
|
import { Rank } from './rank.model';
|
||
|
import { RankService } from './rank.service';
|
||
|
|
||
|
@Controller('rank')
|
||
|
export class RankController {
|
||
|
constructor(private rankService: RankService) {}
|
||
|
|
||
|
@Get()
|
||
|
async getRankList(): Promise<Rank[]> {
|
||
|
return this.rankService.findRankList();
|
||
|
}
|
||
|
|
||
|
@UseGuards(JwtAuthGuard)
|
||
|
@Get('/:id')
|
||
|
async getUserRank(@Param('id') userId: string): Promise<Rank> {
|
||
|
return this.rankService.findByUserLatest(userId);
|
||
|
}
|
||
|
|
||
|
@UseGuards(JwtAuthGuard)
|
||
|
@Get('/:id/all')
|
||
|
async getUserHistory(@Param('id') userId: string): Promise<Rank[]> {
|
||
|
return this.rankService.findByUser(userId);
|
||
|
}
|
||
|
|
||
|
@UseGuards(JwtAuthGuard)
|
||
|
@Post('/add/20')
|
||
|
async add20Points(@Req() req): Promise<any> {
|
||
|
this.rankService.create(20, req.user.id);
|
||
|
}
|
||
|
|
||
|
@UseGuards(JwtAuthGuard)
|
||
|
@Post('/add/60')
|
||
|
async add60Points(@Req() req): Promise<void> {
|
||
|
this.rankService.create(60, req.user.id);
|
||
|
}
|
||
|
|
||
|
@UseGuards(JwtAuthGuard)
|
||
|
@Post('/add/100')
|
||
|
async add100Points(@Req() req): Promise<void> {
|
||
|
this.rankService.create(100, req.user.id);
|
||
|
}
|
||
|
}
|