forked from StarkMindsHQ/StrellerMinds-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathachievement.controller.ts
More file actions
93 lines (85 loc) · 3.01 KB
/
achievement.controller.ts
File metadata and controls
93 lines (85 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
Controller,
Get,
Post,
Body,
Param,
HttpCode,
HttpStatus,
UseGuards,
Request,
ParseUUIDPipe,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../auth/guards/auth.guard';
import { AchievementService } from '../services/achievement.service';
import { UserProfileService } from '../services/user-profile.service';
import {
AchievementStatsDto,
LeaderboardDto,
AwardBadgeDto,
} from '../dto/achievement.dto';
@ApiTags('Achievements & Badges')
@Controller('achievements')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
export class AchievementController {
constructor(
private readonly achievementService: AchievementService,
private readonly userProfileService: UserProfileService,
) {}
@Get('badges/all')
@ApiOperation({ summary: 'Get all badges' })
@ApiResponse({ status: 200, description: 'Badges retrieved' })
async getAllBadges(): Promise<any[]> {
return this.achievementService.getAllBadges();
}
@Get('badges/:badgeId')
@ApiOperation({ summary: 'Get badge details' })
@ApiResponse({ status: 200, description: 'Badge retrieved' })
async getBadge(
@Param('badgeId', new ParseUUIDPipe()) badgeId: string,
): Promise<any> {
return this.achievementService.getBadgeById(badgeId);
}
@Post('me/award')
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Award badge to current user (admin only)' })
@ApiResponse({ status: 201, description: 'Badge awarded' })
async awardBadge(
@Request() req,
@Body() awardDto: AwardBadgeDto,
): Promise<any> {
const profile = await this.userProfileService.getProfileByUserId(req.user.id);
return this.achievementService.awardBadgeToUser(profile.id, awardDto);
}
@Get('me/stats')
@ApiOperation({ summary: 'Get my achievement stats' })
@ApiResponse({ status: 200, description: 'Stats retrieved' })
async getMyStats(@Request() req): Promise<AchievementStatsDto> {
const profile = await this.userProfileService.getProfileByUserId(req.user.id);
return this.achievementService.getAchievementStats(profile.id);
}
@Get(':userId/stats')
@ApiOperation({ summary: 'Get user achievement stats' })
@ApiResponse({ status: 200, description: 'Stats retrieved' })
async getUserStats(
@Param('userId', new ParseUUIDPipe()) userId: string,
): Promise<AchievementStatsDto> {
const profile = await this.userProfileService.getProfileByUserId(userId);
return this.achievementService.getAchievementStats(profile.id);
}
@Get('leaderboard')
@ApiOperation({ summary: 'Get achievement leaderboard' })
@ApiResponse({ status: 200, description: 'Leaderboard retrieved' })
async getLeaderboard(
): Promise<LeaderboardDto[]> {
return this.achievementService.getLeaderboard(50, 0);
}
@Get('badges/search')
@ApiOperation({ summary: 'Search badges' })
@ApiResponse({ status: 200, description: 'Search results' })
async searchBadges(): Promise<any[]> {
return this.achievementService.getAllBadges();
}
}