add previous days query to player history
All checks were successful
Deploy Backend / docker (ubuntu-latest) (push) Successful in 39s

This commit is contained in:
Lee 2024-10-23 09:02:11 +01:00
parent 55cbcb3d66
commit c09a50b8a2

@ -7,24 +7,32 @@ import { AroundPlayerResponse } from "@ssr/common/response/around-player-respons
@Controller("/player") @Controller("/player")
export default class PlayerController { export default class PlayerController {
@Get("/history/:id", { @Get("/history/:id/:days", {
config: {}, config: {},
params: t.Object({ params: t.Object({
id: t.String({ required: true }), id: t.String({ required: true }),
days: t.Number({ default: 50, required: false }),
}), }),
query: t.Object({ query: t.Object({
createIfMissing: t.Boolean({ default: false, required: false }), createIfMissing: t.Boolean({ default: false, required: false }),
}), }),
}) })
public async getPlayer({ public async getPlayer({
params: { id }, params: { id, days },
query: { createIfMissing }, query: { createIfMissing },
}: { }: {
params: { id: string }; params: { id: string; days: number };
query: { createIfMissing: boolean }; query: { createIfMissing: boolean };
}): Promise<{ statistics: Record<string, PlayerHistory> }> { }): Promise<{ statistics: Record<string, PlayerHistory> }> {
if (days < 1) {
days = 1;
}
// Limit to 10 years
if (days > 365 * 10) {
days = 365 * 10;
}
const player = await PlayerService.getPlayer(id, createIfMissing); const player = await PlayerService.getPlayer(id, createIfMissing);
return { statistics: player.getHistoryPreviousDays(50) }; return { statistics: player.getHistoryPreviousDays(days) };
} }
@Get("/tracked/:id", { @Get("/tracked/:id", {