@@ -34,9 +34,10 @@ import PlayerInMatchEntity from 'gameserver/model/player-in-match.entity';
34
34
import FinishedMatchEntity from 'gameserver/model/finished-match.entity' ;
35
35
import { makePage } from 'gateway/util/make-page' ;
36
36
import { ProcessRankedMatchHandler } from 'gameserver/command/ProcessRankedMatch/process-ranked-match.handler' ;
37
+ import { AchievementKey } from 'gateway/shared-types/achievemen-key' ;
37
38
38
- @Controller ( ' player' )
39
- @ApiTags ( ' player' )
39
+ @Controller ( " player" )
40
+ @ApiTags ( " player" )
40
41
export class PlayerController {
41
42
private static leaderboardLimit = 1000 ;
42
43
@@ -60,30 +61,45 @@ export class PlayerController {
60
61
private readonly achievementEntityRepository : Repository < AchievementEntity > ,
61
62
) { }
62
63
63
- @Get ( ' /:id/achievements' )
64
+ @Get ( " /:id/achievements" )
64
65
public async playerAchievements (
65
- @Param ( 'id' ) steamId : string ,
66
+ @Param ( "id" ) steamId : string ,
66
67
) : Promise < AchievementDto [ ] > {
67
68
const ach = Array . from ( this . achievements . achievementMap . values ( ) ) ;
68
69
69
70
const achievementsQ = this . achievementEntityRepository
70
- . createQueryBuilder ( 'a' )
71
+ . createQueryBuilder ( "a" )
71
72
. leftJoinAndMapOne (
72
- ' a.match' ,
73
+ " a.match" ,
73
74
FinishedMatchEntity ,
74
- 'fm' ,
75
+ "fm" ,
75
76
'fm.id = a."matchId"' ,
76
77
)
77
78
. leftJoinAndMapOne (
78
- ' a.pim' ,
79
+ " a.pim" ,
79
80
PlayerInMatchEntity ,
80
- ' pim' ,
81
+ " pim" ,
81
82
`pim."playerId" = a.steam_id and pim."matchId" = a."matchId"` ,
82
83
)
83
84
. where ( { steam_id : steamId } ) ;
84
85
85
86
const achievements = await achievementsQ . getMany ( ) ;
86
- return achievements . map ( t => {
87
+
88
+ const paddedAchievements = Object . keys ( AchievementKey )
89
+ . filter (
90
+ ( key ) =>
91
+ isNaN ( Number ( key ) ) &&
92
+ achievements . findIndex (
93
+ ( ach ) => ach . achievement_key === Number ( key ) ,
94
+ ) === - 1 ,
95
+ )
96
+ . map ( ( key ) => ( {
97
+ steam_id : steamId ,
98
+ progress : 0 ,
99
+ achievement_key : AchievementKey [ key ] ,
100
+ } as AchievementEntity ) ) ;
101
+
102
+ return achievements . concat ( paddedAchievements ) . map ( ( t ) => {
87
103
if ( t . match ) {
88
104
t . match . players = [ ] ;
89
105
}
@@ -92,18 +108,18 @@ export class PlayerController {
92
108
}
93
109
94
110
@ApiQuery ( {
95
- name : ' page' ,
111
+ name : " page" ,
96
112
required : true ,
97
113
} )
98
114
@ApiQuery ( {
99
- name : ' per_page' ,
115
+ name : " per_page" ,
100
116
required : false ,
101
117
} )
102
118
@Get ( `/:id/teammates` )
103
119
async playerTeammates (
104
- @Param ( 'id' ) steamId : string ,
105
- @Query ( ' page' , NullableIntPipe ) page : number ,
106
- @Query ( ' per_page' , NullableIntPipe ) perPage : number = 25 ,
120
+ @Param ( "id" ) steamId : string ,
121
+ @Query ( " page" , NullableIntPipe ) page : number ,
122
+ @Query ( " per_page" , NullableIntPipe ) perPage : number = 25 ,
107
123
) : Promise < PlayerTeammatePage > {
108
124
const totalEntries = await this . connection . query < { count : number } [ ] > (
109
125
`select count(distinct pim."playerId")::int
@@ -154,10 +170,10 @@ offset $2 limit $3`,
154
170
}
155
171
156
172
@CacheTTL ( 120 )
157
- @Get ( ' /summary/:version/:id' )
173
+ @Get ( " /summary/:version/:id" )
158
174
async playerSummary (
159
- @Param ( ' version' ) version : Dota2Version ,
160
- @Param ( 'id' ) steam_id : string ,
175
+ @Param ( " version" ) version : Dota2Version ,
176
+ @Param ( "id" ) steam_id : string ,
161
177
) : Promise < PlayerSummaryDto > {
162
178
await this . cbus . execute ( new MakeSureExistsCommand ( new PlayerId ( steam_id ) ) ) ;
163
179
@@ -187,13 +203,15 @@ offset $2 limit $3`,
187
203
? 0
188
204
: Math . max ( 0 , UNRANKED_GAMES_REQUIRED_FOR_RANKED - lb . games ) ,
189
205
190
- calibrationGamesLeft : Math . max ( ProcessRankedMatchHandler . TOTAL_CALIBRATION_GAMES - lb . ranked_games , 0 )
206
+ calibrationGamesLeft : Math . max (
207
+ ProcessRankedMatchHandler . TOTAL_CALIBRATION_GAMES - lb . ranked_games ,
208
+ 0 ,
209
+ ) ,
191
210
} ;
192
211
}
193
212
194
- const summary : Summary | undefined = await this . playerService . fullSummary (
195
- steam_id ,
196
- ) ;
213
+ const summary : Summary | undefined =
214
+ await this . playerService . fullSummary ( steam_id ) ;
197
215
198
216
const rank = await this . playerService . getRank ( version , steam_id ) ;
199
217
@@ -221,27 +239,31 @@ offset $2 limit $3`,
221
239
( summary ?. unranked_games || 0 ) ,
222
240
) ,
223
241
224
- calibrationGamesLeft : Math . max ( ProcessRankedMatchHandler . TOTAL_CALIBRATION_GAMES - ( summary ?. ranked_games || 0 ) , 0 )
242
+ calibrationGamesLeft : Math . max (
243
+ ProcessRankedMatchHandler . TOTAL_CALIBRATION_GAMES -
244
+ ( summary ?. ranked_games || 0 ) ,
245
+ 0 ,
246
+ ) ,
225
247
} ;
226
248
}
227
249
228
- @Get ( ' /leaderboard' )
250
+ @Get ( " /leaderboard" )
229
251
@CacheTTL ( 60 * 30 )
230
252
@ApiQuery ( {
231
- name : ' page' ,
253
+ name : " page" ,
232
254
required : true ,
233
255
} )
234
256
@ApiQuery ( {
235
- name : ' per_page' ,
257
+ name : " per_page" ,
236
258
required : false ,
237
259
} )
238
260
async leaderboard (
239
- @Query ( ' page' , NullableIntPipe ) page : number ,
240
- @Query ( ' per_page' , NullableIntPipe ) perPage : number = 100 ,
261
+ @Query ( " page" , NullableIntPipe ) page : number ,
262
+ @Query ( " per_page" , NullableIntPipe ) perPage : number = 100 ,
241
263
) : Promise < LeaderboardEntryPageDto > {
242
264
const [ data , total ] = await this . leaderboardViewRepository . findAndCount ( {
243
265
order : {
244
- mmr : ' DESC' ,
266
+ mmr : " DESC" ,
245
267
} ,
246
268
take : perPage ,
247
269
skip : perPage * page ,
@@ -253,21 +275,21 @@ offset $2 limit $3`,
253
275
@CacheTTL ( 120 )
254
276
@Get ( `/summary/heroes/:version/:id` )
255
277
async playerHeroSummary (
256
- @Param ( ' version' ) version : Dota2Version ,
257
- @Param ( 'id' ) steam_id : string ,
278
+ @Param ( " version" ) version : Dota2Version ,
279
+ @Param ( "id" ) steam_id : string ,
258
280
) : Promise < HeroStatsDto [ ] > {
259
281
await this . cbus . execute ( new MakeSureExistsCommand ( new PlayerId ( steam_id ) ) ) ;
260
282
261
283
return await this . playerService . heroStats ( version , steam_id ) ;
262
284
}
263
285
264
- @Get ( ' /hero/:hero/players' )
265
- async getHeroPlayers ( @Param ( ' hero' ) hero : string ) {
286
+ @Get ( " /hero/:hero/players" )
287
+ async getHeroPlayers ( @Param ( " hero" ) hero : string ) {
266
288
return this . playerService . getHeroPlayers ( hero ) ;
267
289
}
268
290
269
291
@Get ( `/ban_info/:id` )
270
- async banInfo ( @Param ( 'id' ) steam_id : string ) : Promise < BanStatusDto > {
292
+ async banInfo ( @Param ( "id" ) steam_id : string ) : Promise < BanStatusDto > {
271
293
const ban = await this . playerBanRepository . findOne ( {
272
294
where : { steam_id : steam_id } ,
273
295
} ) ;
@@ -280,7 +302,7 @@ offset $2 limit $3`,
280
302
} ;
281
303
}
282
304
283
- @Post ( ' /report' )
305
+ @Post ( " /report" )
284
306
async reportPlayer ( @Body ( ) dto : ReportPlayerDto ) {
285
307
this . ebus . publish (
286
308
new PlayerReportEvent ( dto . matchId , dto . reporter , dto . reported , dto . text ) ,
0 commit comments