LETS GO BABY
This commit is contained in:
54
projects/backend/src/controller/player.controller.ts
Normal file
54
projects/backend/src/controller/player.controller.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { Controller, Get } from "elysia-decorators";
|
||||
import { PlayerService } from "../service/player.service";
|
||||
import { t } from "elysia";
|
||||
import { PlayerHistory } from "@ssr/common/types/player/player-history";
|
||||
import { PlayerTrackedSince } from "@ssr/common/types/player/player-tracked-since";
|
||||
|
||||
@Controller("/player")
|
||||
export default class PlayerController {
|
||||
@Get("/history/:id", {
|
||||
config: {},
|
||||
params: t.Object({
|
||||
id: t.String({ required: true }),
|
||||
}),
|
||||
query: t.Object({
|
||||
createIfMissing: t.Boolean({ default: false, required: false }),
|
||||
}),
|
||||
})
|
||||
public async getPlayer({
|
||||
params: { id },
|
||||
query: { createIfMissing },
|
||||
}: {
|
||||
params: { id: string };
|
||||
query: { createIfMissing: boolean };
|
||||
}): Promise<{ statistics: Record<string, PlayerHistory> }> {
|
||||
const player = await PlayerService.getPlayer(id, createIfMissing);
|
||||
return { statistics: player.getHistoryPreviousDays(50) };
|
||||
}
|
||||
|
||||
@Get("/tracked/:id", {
|
||||
config: {},
|
||||
params: t.Object({
|
||||
id: t.String({ required: true }),
|
||||
}),
|
||||
})
|
||||
public async getTrackedStatus({
|
||||
params: { id },
|
||||
query: { createIfMissing },
|
||||
}: {
|
||||
params: { id: string };
|
||||
query: { createIfMissing: boolean };
|
||||
}): Promise<PlayerTrackedSince> {
|
||||
try {
|
||||
const player = await PlayerService.getPlayer(id, createIfMissing);
|
||||
return {
|
||||
tracked: true,
|
||||
daysTracked: player.getDaysTracked(),
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
tracked: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user