-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: takaro-ci-bot[bot] <138661031+takaro-ci-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
62a9ce7
commit 26ca998
Showing
25 changed files
with
1,136 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IsDateString, IsISO8601, IsOptional, IsUUID, ValidateNested } from 'class-validator'; | ||
import { APIOutput, apiResponse } from '@takaro/http'; | ||
import { AuthenticatedRequest, AuthService } from '../service/AuthService.js'; | ||
import { Get, JsonController, UseBefore, Req, QueryParams } from 'routing-controllers'; | ||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; | ||
import { Type } from 'class-transformer'; | ||
import { PERMISSIONS } from '@takaro/auth'; | ||
import { StatsOutputDTO, StatsService } from '../service/StatsService.js'; | ||
import { TakaroDTO } from '@takaro/util'; | ||
|
||
class StatsOutputDTOAPI extends APIOutput<StatsOutputDTO> { | ||
@ValidateNested() | ||
@Type(() => StatsOutputDTO) | ||
declare data: StatsOutputDTO; | ||
} | ||
|
||
class BaseStatsInputDTO extends TakaroDTO<BaseStatsInputDTO> { | ||
@IsISO8601() | ||
@IsDateString() | ||
@IsOptional() | ||
startDate?: string; | ||
@IsOptional() | ||
@IsDateString() | ||
@IsISO8601() | ||
endDate?: string; | ||
} | ||
|
||
class PogStatsInputDTO extends BaseStatsInputDTO { | ||
@IsUUID('4') | ||
gameServerId!: string; | ||
@IsUUID('4') | ||
playerId!: string; | ||
} | ||
|
||
class PlayersOnlineInputDTO extends BaseStatsInputDTO { | ||
@IsOptional() | ||
@IsUUID('4') | ||
gameServerId?: string; | ||
} | ||
|
||
@OpenAPI({ | ||
security: [{ domainAuth: [] }], | ||
}) | ||
@JsonController() | ||
export class StatsController { | ||
@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.READ_GAMESERVERS, PERMISSIONS.READ_PLAYERS])) | ||
@ResponseSchema(StatsOutputDTOAPI) | ||
@Get('/stats/ping') | ||
async getPingStats(@Req() req: AuthenticatedRequest, @QueryParams() query: PogStatsInputDTO) { | ||
const service = new StatsService(req.domainId); | ||
return apiResponse(await service.getPing(query.playerId, query.gameServerId, query.startDate, query.endDate)); | ||
} | ||
|
||
@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.READ_GAMESERVERS, PERMISSIONS.READ_PLAYERS])) | ||
@ResponseSchema(StatsOutputDTOAPI) | ||
@Get('/stats/currency') | ||
async getCurrencyStats(@Req() req: AuthenticatedRequest, @QueryParams() query: PogStatsInputDTO) { | ||
const service = new StatsService(req.domainId); | ||
return apiResponse(await service.getCurrency(query.playerId, query.gameServerId, query.startDate, query.endDate)); | ||
} | ||
|
||
@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.READ_GAMESERVERS, PERMISSIONS.READ_PLAYERS])) | ||
@ResponseSchema(StatsOutputDTOAPI) | ||
@Get('/stats/players-online') | ||
async getPlayerOnlineStats(@Req() req: AuthenticatedRequest, @QueryParams() query: PlayersOnlineInputDTO) { | ||
const service = new StatsService(req.domainId); | ||
return apiResponse(await service.getPlayersOnline(query.gameServerId, query.startDate, query.endDate)); | ||
} | ||
} |
Oops, something went wrong.