More service naming consistency cleanup
This commit is contained in:
+23
-22
@@ -22,9 +22,10 @@ import { StandardsParametersSchema } from "@blade-and-brawn/calculator";
|
||||
|
||||
// SERVICES
|
||||
// -----------
|
||||
|
||||
const calculatorService = new CalculatorService();
|
||||
const commerceService = new CommerceService();
|
||||
const s = {
|
||||
Calculator: new CalculatorService(),
|
||||
Commerce: new CommerceService()
|
||||
};
|
||||
|
||||
// ELYSIA
|
||||
// -----------
|
||||
@@ -103,7 +104,7 @@ export const app = new Elysia()
|
||||
(app) => app
|
||||
// Non-authenticated
|
||||
.post("/calculate", async ({ body }) => {
|
||||
return { levels: calculatorService.calculate(body.player, body.activityPerformances) };
|
||||
return { levels: s.Calculator.calculate(body.player, body.activityPerformances) };
|
||||
}, {
|
||||
body: t.Object({
|
||||
player: PlayerSchema,
|
||||
@@ -117,23 +118,23 @@ export const app = new Elysia()
|
||||
return { sessionId: token.sessionId.toString() };
|
||||
})
|
||||
.put("/config/:id", async ({ params: { id }, body: { datasetId, parameters } }) => {
|
||||
await calculatorService.standards.setConfig(id, datasetId, parameters);
|
||||
await s.Calculator.Standards.Config.update(id, datasetId, parameters);
|
||||
}, {
|
||||
params: t.Object({ id: t.String() }),
|
||||
body: t.Object({ datasetId: t.String(), parameters: StandardsParametersSchema })
|
||||
})
|
||||
.post("/config", async ({ body: { datasetId, parameters } }) => {
|
||||
await calculatorService.standards.createConfig(datasetId, parameters);
|
||||
await s.Calculator.Standards.Config.create(datasetId, parameters);
|
||||
}, {
|
||||
body: t.Object({ datasetId: t.String(), parameters: StandardsParametersSchema })
|
||||
})
|
||||
.post("/config/:id/select", async ({ params: { id } }) => {
|
||||
await calculatorService.standards.selectConfig(id);
|
||||
.post("/config/:id/switch", async ({ params: { id } }) => {
|
||||
await s.Calculator.Standards.Config.switch(id);
|
||||
}, {
|
||||
params: t.Object({ id: t.String() })
|
||||
})
|
||||
.get("/config", async () => {
|
||||
return await calculatorService.standards.getSelectedConfig();
|
||||
return await s.Calculator.Standards.Config.get();
|
||||
})
|
||||
)
|
||||
|
||||
@@ -149,17 +150,17 @@ export const app = new Elysia()
|
||||
app
|
||||
// Sync status
|
||||
.get("/", async ({ sessionId }) => {
|
||||
const latestSync = await commerceService.getLatestSync(sessionId);
|
||||
const latestSync = await s.Commerce.Sync.getLatest(sessionId);
|
||||
if (!latestSync) throw new NotFoundError("No sync found");
|
||||
return {
|
||||
startDate: latestSync.started_at,
|
||||
status: commerceService.deriveSyncStatus(latestSync),
|
||||
status: s.Commerce.Sync.deriveStatus(latestSync),
|
||||
syncingPrintfulProductIds: latestSync.syncing_printful_product_ids
|
||||
}
|
||||
})
|
||||
// Run sync
|
||||
.post("/:printfulProductId?", async ({ params: { printfulProductId }, sessionId }) => {
|
||||
await commerceService.sync({
|
||||
await s.Commerce.Sync.start({
|
||||
session: { id: sessionId, name: "Portal" },
|
||||
filter: {
|
||||
printfulProductIds: printfulProductId ? [printfulProductId] : null
|
||||
@@ -168,13 +169,13 @@ export const app = new Elysia()
|
||||
}, { params: t.Object({ printfulProductId: t.Optional(t.Numeric()) }) }),
|
||||
)
|
||||
.get("/:printfulProductId", async ({ params: { printfulProductId } }) => {
|
||||
const printfulProduct = await commerceService.printful.Products.get(printfulProductId);
|
||||
const printfulProduct = await s.Commerce.Printful.Products.get(printfulProductId);
|
||||
if (!printfulProduct) throw new NotFoundError("Missing printful product");
|
||||
|
||||
const webflowProductId = printfulProduct.sync_product.external_id.split("-")[0];
|
||||
if (!webflowProductId) throw new NotFoundError("Missing webflow product ID");
|
||||
|
||||
const webflowProduct = await commerceService.webflow.Products.get(webflowProductId);
|
||||
const webflowProduct = await s.Commerce.Webflow.Products.get(webflowProductId);
|
||||
|
||||
return { printfulProduct, webflowProduct };
|
||||
}, {
|
||||
@@ -192,7 +193,7 @@ export const app = new Elysia()
|
||||
const printfulProduct = payload.data.sync_product;
|
||||
log.info({ productId: printfulProduct.id }, "printful webhook: product updated");
|
||||
|
||||
await commerceService.sync({
|
||||
await s.Commerce.Sync.start({
|
||||
session: { id: randomUUIDv7(), name: "Printful" },
|
||||
filter: {
|
||||
printfulProductIds: [printfulProduct.id]
|
||||
@@ -206,7 +207,7 @@ export const app = new Elysia()
|
||||
log.info({ externalId: payload.data.sync_product.external_id, webflowProductId }, "printful webhook: product deleted");
|
||||
if (!webflowProductId) throw new NotFoundError("Missing webflow product ID");
|
||||
|
||||
await commerceService.webflow.Products.remove(webflowProductId);
|
||||
await s.Commerce.Webflow.Products.remove(webflowProductId);
|
||||
break;
|
||||
}
|
||||
case Printful.Webhook.Event.PackageShipped: {
|
||||
@@ -214,12 +215,12 @@ export const app = new Elysia()
|
||||
const shipInfo = payload.data.shipment;
|
||||
log.info({ webflowOrderId, carrier: shipInfo.carrier, tracking: shipInfo.tracking_number }, "printful webhook: package shipped");
|
||||
|
||||
await commerceService.webflow.Orders.update(webflowOrderId, {
|
||||
await s.Commerce.Webflow.Orders.update(webflowOrderId, {
|
||||
shippingTrackingURL: shipInfo.tracking_url,
|
||||
shippingTracking: shipInfo.tracking_number,
|
||||
shippingProvider: shipInfo.carrier,
|
||||
});
|
||||
await commerceService.webflow.Orders.fulfill(webflowOrderId, {
|
||||
await s.Commerce.Webflow.Orders.fulfill(webflowOrderId, {
|
||||
sendOrderFulfilledEmail: true,
|
||||
});
|
||||
break;
|
||||
@@ -229,7 +230,7 @@ export const app = new Elysia()
|
||||
}
|
||||
})
|
||||
.post("/webhook/webflow", async ({ request, body }) => {
|
||||
if (!commerceService.webflow.Util.verifyWebflowSignature(request, body))
|
||||
if (!s.Commerce.Webflow.Util.verifyWebflowSignature(request, body))
|
||||
throw status(400, "Invalid signature");
|
||||
|
||||
const payload = body as Webflow.Webhook.EventPayload;
|
||||
@@ -239,7 +240,7 @@ export const app = new Elysia()
|
||||
const webflowOrder = payload.payload;
|
||||
log.info({ orderId: webflowOrder.orderId }, "webflow webhook: order created");
|
||||
|
||||
await commerceService.printful.Orders.create({
|
||||
await s.Commerce.Printful.Orders.create({
|
||||
external_id: webflowOrder.orderId,
|
||||
// TODO: derive from webflow
|
||||
shipping: "STANDARD",
|
||||
@@ -272,8 +273,8 @@ app.listen(3000, async () => {
|
||||
log.info({ port: 3000 }, "server started")
|
||||
|
||||
try {
|
||||
const frontQueuedSync = await commerceService.queue.front();
|
||||
if (frontQueuedSync) await commerceService.sync(frontQueuedSync);
|
||||
const frontQueuedSync = await s.Commerce.Sync.Queue.front();
|
||||
if (frontQueuedSync) await s.Commerce.Sync.start(frontQueuedSync);
|
||||
}
|
||||
catch (err) {
|
||||
log.error({ err }, "failed to resume product sync queue")
|
||||
|
||||
Reference in New Issue
Block a user