Files
aaaa/src/routes/api/routes/players.ts
2025-09-21 17:47:28 -04:00

37 lines
1.4 KiB
TypeScript

import z from "zod";
import { createHonoRoute } from "../../../util/import.ts";
import { authenticate, statusResponse } from "../../../util/api.ts";
import { typedZValidator } from "../../../util/validators.ts";
import Server from "../../../server/server.ts";
import { HTTPStatus } from "@oneday/http-status";
export const route = createHonoRoute("/players");
route.app.get('/v2/progression/bulk', c => {
return c.json([]); // todo: progression
});
const getProgParamSchema = z.object({
id: z.coerce.number()
});
route.app.get('/v1/progression/:id', typedZValidator('param', getProgParamSchema), async c => {
const prof = await Server.Profiles.get(c.req.valid('param').id);
if (!prof) return statusResponse(c, HTTPStatus.NotFound);
return c.json(await prof.Progression.get());
});
const getProgBulkBodySchema = z.object({
Ids: z.union([z.array(z.coerce.number()), z.coerce.number()])
});
route.app.post('/v1/progression/bulk', authenticate, typedZValidator('json', getProgBulkBodySchema), async c => {
const ids = c.req.valid('json').Ids;
if (typeof ids == 'object') {
const profs = await Server.Profiles.getMany(...ids);
return c.json(await Promise.all(profs.map(prof => prof.Progression.get())));
} else {
const prof = await Server.Profiles.get(ids);
if (!prof) return c.json([]);
return c.json([await prof.Progression.get()]);
}
});