32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import Elysia, { NotFoundError, t } from "elysia";
|
|
import { ActivityPerformanceSchema, PlayerSchema } from "@blade-and-brawn/domain";
|
|
import { authPlugin } from "../plugins/auth";
|
|
import { s } from "../services";
|
|
import { BigIntIdSchema } from "../util/models";
|
|
|
|
const AssessmentsController = new Elysia({ prefix: "/assessments" })
|
|
.use(authPlugin)
|
|
.guard({ authAdmin: true })
|
|
.post("/", async ({ body: { player, activityPerformances, id } }) => {
|
|
return await s.Assessments.create(player, activityPerformances, id);
|
|
}, {
|
|
body: t.Object({
|
|
player: PlayerSchema,
|
|
activityPerformances: t.Array(ActivityPerformanceSchema),
|
|
id: t.Optional(t.String()),
|
|
})
|
|
})
|
|
.put("/:id", async ({ body: { player, activityPerformances }, params: { id } }) => {
|
|
const updated = await s.Assessments.update(id, player, activityPerformances);
|
|
if (!updated) throw new NotFoundError("Assessment not found");
|
|
return updated;
|
|
}, {
|
|
params: t.Object({ id: BigIntIdSchema }),
|
|
body: t.Object({
|
|
player: PlayerSchema,
|
|
activityPerformances: t.Array(ActivityPerformanceSchema),
|
|
})
|
|
});
|
|
|
|
export default AssessmentsController;
|