Some api cleanup

This commit is contained in:
Dominic Ferrando
2026-06-23 12:26:08 -04:00
parent 6fa3d78571
commit 736c770647
+24 -24
View File
@@ -11,7 +11,7 @@ import {
type Player,
} from "@blade-and-brawn/domain"
import { cors } from "@elysiajs/cors";
import { Elysia, NotFoundError } from "elysia";
import { Elysia, NotFoundError, status } from "elysia";
import {
PrintfulService,
SyncService,
@@ -77,25 +77,27 @@ export const app = new Elysia()
// CALCULATOR
.post("/calculate", async ({ body }) => {
const output = {
return {
levels: levelCalculator.calculate(body.player, body.activityPerformances),
};
// console.log({ log: query?.log });
// if (query?.log === "true") {
// void fetch("https://kv-logger.xominus.workers.dev", {
// method: "POST",
// headers: { "content-type": "application/json" },
// body: JSON.stringify({ output, player, activityPerformances }),
// }).catch(() => {});
// }
return output;
}, {
body: z.object({
player: PlayerSchema,
activityPerformances: z.array(ActivityPerformanceSchema)
})
}),
// afterResponse: ({ query, body, responseValue }) => {
// if (query.log === "true") {
// void fetch("https://kv-logger.xominus.workers.dev", {
// method: "POST",
// headers: { "content-type": "application/json" },
// body: JSON.stringify({
// output: responseValue,
// player: body.player,
// activityPerformances: body.activityPerformances
// }),
// });
// }
// }
})
// COMMERCE
@@ -107,20 +109,18 @@ export const app = new Elysia()
// Sync status
.get("/", async ({ }) => SyncService.state)
// Full sync
.post("/", async ({ set }) => {
if (SyncService.state.isSyncing) {
set.status = 409;
return { error: "Sync already in progress" };
}
.post("/", async ({ }) => {
if (SyncService.state.isSyncing)
return status(409, { error: "Sync already in progress" });
await SyncService.sync();
return { ok: true };
})
// Per-product sync
.post("/:printfulProductId", async ({ params, set }) => {
if (SyncService.state.isSyncing) {
set.status = 409;
return { error: "Sync already in progress" };
}
.post("/:printfulProductId", async ({ params }) => {
if (SyncService.state.isSyncing)
return status(409, { error: "Sync already in progress" });
await SyncService.sync(params.printfulProductId);
return { ok: true };
}, { params: z.object({ printfulProductId: z.number() }) }),