From 736c77064784cd5a0520a70622e11ed6206918ff Mon Sep 17 00:00:00 2001 From: Dominic Ferrando Date: Tue, 23 Jun 2026 12:26:08 -0400 Subject: [PATCH] Some api cleanup --- apps/api/src/index.ts | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 5b850a4..2d808dd 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -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() }) }),