diff --git a/server/src/api.ts b/server/src/api.ts index c36fe8d..97c87fa 100644 --- a/server/src/api.ts +++ b/server/src/api.ts @@ -14,9 +14,7 @@ import fs from 'fs'; import { RoundRepository } from './repository/round'; import { PaginationParams, pagination } from './middlewares/pagination'; import { CSPRCloudAPIClient } from './cspr-cloud/api-client'; -import { PlayEventPayload, isPlayDeploy, isEvent, isPlayEventPayload } from './events'; -import { trackPlay } from './event-handler'; -import { raw } from 'mysql2'; +import { isPlayDeploy } from './events'; import { Play } from './entity/play.entity'; const app: Express = express(); @@ -31,6 +29,7 @@ const wss = new WebSocket.Server({ server }); interface FindPlaysQuery extends PaginationParams { player_account_hash: string; + deploy_hash: string; } async function initAPI() { @@ -41,6 +40,9 @@ async function initAPI() { const csprCloudClient = new CSPRCloudAPIClient(config.csprCloudApiUrl, config.csprCloudAccessKey); + /** + * @deprecated Use GET /plays?player_account_hash=... + */ app.get('/playsByPlayer', pagination(), async (req: Request, res: Response) => { const [plays, total] = await playsRepository.findByPlayer(req.query.player_account_hash, { limit: req.query.limit, @@ -53,7 +55,16 @@ async function initAPI() { }); app.get('/plays', pagination(), async (req: Request, res: Response) => { - const [plays, total] = await playsRepository.getPaginatedPlays({ + const filters = {}; + if (req.query.player_account_hash) { + filters['playerAccountHash'] = req.query.player_account_hash; + } + + if (req.query.deploy_hash) { + filters['deployHash'] = req.query.deploy_hash; + } + + const [plays, total] = await playsRepository.getPaginatedPlays(filters, { limit: req.query.limit, offset: req.query.offset, }); @@ -89,6 +100,9 @@ async function initAPI() { } }); + /** + * @deprecated Use GET /plays?deploy_hash=... + */ app.get('/playByDeployHash', async (req: Request, res: Response) => { if (req.query.deployHash === null) { res.status(400).send('No deploy hash provided'); diff --git a/server/src/repository/play.ts b/server/src/repository/play.ts index 0f87ec4..cd09eba 100644 --- a/server/src/repository/play.ts +++ b/server/src/repository/play.ts @@ -7,6 +7,9 @@ export class PlayRepository { this.repo = dataSource.getRepository(Play); } + /** + * @deprecated Use getPaginatedPlays + */ findByPlayer(playerAccountHash: string, paginationParams: { limit: number; offset: number }) { return this.repo.findAndCount({ where: { @@ -17,6 +20,9 @@ export class PlayRepository { }); } + /** + * @deprecated Use getPaginatedPlays + */ findByDeployHash(deployHash: string): Promise { return this.repo.findOne({ where: { @@ -25,8 +31,9 @@ export class PlayRepository { }); } - getPaginatedPlays(paginationParams: { limit: number; offset: number }): Promise<[Play[], number]> { + getPaginatedPlays(filters, paginationParams: { limit: number; offset: number }): Promise<[Play[], number]> { return this.repo.findAndCount({ + where: filters, take: paginationParams.limit, skip: paginationParams.offset, order: { diff --git a/server/src/repository/round.ts b/server/src/repository/round.ts index 968cfc5..5e2d3df 100644 --- a/server/src/repository/round.ts +++ b/server/src/repository/round.ts @@ -8,6 +8,11 @@ export class RoundRepository { this.repo = dataSource.getRepository(Round); } + /** + * @todo Switch to paginationParams (same as in the play repository) + * @param limit + * @param offset + */ async getRounds(limit: number, offset: number): Promise<[Round[], number]> { const queryBuilder = this.repo .createQueryBuilder('p')