Make products table more consistent with other tables
This commit is contained in:
+21
-9
@@ -13,7 +13,7 @@ import {
|
||||
import { DEFAULT_NAME, env, log } from "./util";
|
||||
import serverTiming from "@elysia/server-timing";
|
||||
import jwt from "@elysia/jwt";
|
||||
import { CommerceService } from "./services/commerce";
|
||||
import { CommerceService, WOrderStatusSchema } from "./services/commerce";
|
||||
import cluster from "node:cluster";
|
||||
import { randomUUIDv7, sleep } from "bun";
|
||||
import { CalculatorService, CalculatorUnavailableError } from "./services/calculator";
|
||||
@@ -201,6 +201,25 @@ export const app = new Elysia()
|
||||
// COMMERCE
|
||||
.group("/commerce", { auth: true }, (app) => app
|
||||
.group("/products", (app) => app
|
||||
.get("/", async ({ query }) => {
|
||||
const pProducts = await s.Commerce.Printful.Products.list({
|
||||
limit: query.limit,
|
||||
offset: query.offset,
|
||||
});
|
||||
const isSyncedFlags = await Promise.all(
|
||||
pProducts.map(async (pProduct) => {
|
||||
const wProductId = pProduct.external_id.split("-")[0];
|
||||
if (!wProductId) return false;
|
||||
return (await s.Commerce.Webflow.Products.get(wProductId)) !== undefined;
|
||||
})
|
||||
);
|
||||
return pProducts.map((pProduct, i) => ({ pProduct, isSynced: isSyncedFlags[i] }));
|
||||
}, {
|
||||
query: t.Object({
|
||||
limit: t.Optional(t.Numeric()),
|
||||
offset: t.Optional(t.Numeric()),
|
||||
})
|
||||
})
|
||||
.group("/sync", (app) => app
|
||||
// Sync status
|
||||
.get("/", async ({ sessionId }) => {
|
||||
@@ -251,14 +270,7 @@ export const app = new Elysia()
|
||||
return wOrders.map((wOrder, i) => ({ wOrder, isSynced: isSyncedFlags[i] }));
|
||||
}, {
|
||||
query: t.Object({
|
||||
status: t.Optional(t.Union([
|
||||
t.Literal("pending"),
|
||||
t.Literal("unfulfilled"),
|
||||
t.Literal("fulfilled"),
|
||||
t.Literal("disputed"),
|
||||
t.Literal("dispute-lost"),
|
||||
t.Literal("refunded"),
|
||||
])),
|
||||
status: t.Optional(WOrderStatusSchema),
|
||||
limit: t.Optional(t.Numeric()),
|
||||
offset: t.Optional(t.Numeric()),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user