Finish adding config endpoints

This commit is contained in:
Dominic Ferrando
2026-07-04 02:32:59 -04:00
parent f85225e08f
commit c1d3bed404
4 changed files with 131 additions and 7 deletions
+22 -5
View File
@@ -18,6 +18,7 @@ import { CommerceService } from "./services/commerce";
import cluster from "node:cluster";
import { randomUUIDv7 } from "bun";
import { CalculatorService } from "./services/calculator";
import { StandardsConfigSchema } from "@blade-and-brawn/calculator";
// SERVICES
// -----------
@@ -100,6 +101,7 @@ export const app = new Elysia()
// CALCULATOR
.group("/calculator",
(app) => app
// Non-authenticated
.post("/calculate", async ({ body }) => {
return { levels: calculatorService.calculate(body.player, body.activityPerformances) };
}, {
@@ -108,15 +110,30 @@ export const app = new Elysia()
activityPerformances: t.Array(ActivityPerformanceSchema)
}),
})
// Authenticated
.resolve(async ({ jwt, cookie: { auth } }) => {
const token = auth.value && await jwt.verify(auth.value);
if (!token || !token.sessionId) throw status(401, "Unauthorized");
return { sessionId: token.sessionId.toString() };
})
.post("/config", () => { })
.put("/config/:id", async ({ params: { id }, body: { standardsConfig } }) => {
await calculatorService.setConfig(id, standardsConfig);
}, {
params: t.Object({ id: t.String() }),
body: t.Object({ standardsConfig: StandardsConfigSchema })
})
.post("/config", async ({ body: { standardsConfig } }) => {
await calculatorService.createConfig(standardsConfig);
}, {
body: t.Object({ standardsConfig: StandardsConfigSchema })
})
.post("/config/:id/select", async ({ params: { id } }) => {
await calculatorService.selectConfig(id);
}, {
params: t.Object({ id: t.String() })
})
.get("/config", async () => {
const config = await calculatorService.getConfig();
return config;
return await calculatorService.getSelectedConfig();
})
)
@@ -150,8 +167,8 @@ export const app = new Elysia()
});
}, { params: t.Object({ printfulProductId: t.Optional(t.Numeric()) }) }),
)
.get("/:printfulProductId", async ({ params }) => {
const printfulProduct = await commerceService.printful.Products.get(params.printfulProductId);
.get("/:printfulProductId", async ({ params: { printfulProductId } }) => {
const printfulProduct = await commerceService.printful.Products.get(printfulProductId);
if (!printfulProduct) throw new NotFoundError("Missing printful product");
const webflowProductId = printfulProduct.sync_product.external_id.split("-")[0];