From c09a50b8a2debc41a8232c47900eae410c3082d7 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 23 Oct 2024 09:02:11 +0100 Subject: [PATCH] add previous days query to player history --- .../backend/src/controller/player.controller.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/projects/backend/src/controller/player.controller.ts b/projects/backend/src/controller/player.controller.ts index a3d958d..d977d63 100644 --- a/projects/backend/src/controller/player.controller.ts +++ b/projects/backend/src/controller/player.controller.ts @@ -7,24 +7,32 @@ import { AroundPlayerResponse } from "@ssr/common/response/around-player-respons @Controller("/player") export default class PlayerController { - @Get("/history/:id", { + @Get("/history/:id/:days", { config: {}, params: t.Object({ id: t.String({ required: true }), + days: t.Number({ default: 50, required: false }), }), query: t.Object({ createIfMissing: t.Boolean({ default: false, required: false }), }), }) public async getPlayer({ - params: { id }, + params: { id, days }, query: { createIfMissing }, }: { - params: { id: string }; + params: { id: string; days: number }; query: { createIfMissing: boolean }; }): Promise<{ statistics: Record }> { + if (days < 1) { + days = 1; + } + // Limit to 10 years + if (days > 365 * 10) { + days = 365 * 10; + } const player = await PlayerService.getPlayer(id, createIfMissing); - return { statistics: player.getHistoryPreviousDays(50) }; + return { statistics: player.getHistoryPreviousDays(days) }; } @Get("/tracked/:id", {