Per item sync bugfix and cleanup
This commit is contained in:
+8
-14
@@ -101,9 +101,7 @@ export const app = new Elysia()
|
||||
})
|
||||
|
||||
.onAfterResponse(({ request, status, path }) => {
|
||||
const skip: Record<string, string[]> = {
|
||||
"/products/sync/": ["GET"]
|
||||
};
|
||||
const skip: Record<string, string[]> = { "/products/sync/": ["GET"] };
|
||||
if (env.NODE_ENV === "development" && skip[path]?.includes(request.method)) return;
|
||||
|
||||
log.info({
|
||||
@@ -165,16 +163,12 @@ export const app = new Elysia()
|
||||
state: await productSyncer.getState(),
|
||||
isRunning: await productSyncer.isRunning()
|
||||
}))
|
||||
// Full sync
|
||||
.post("/", async ({ }) => {
|
||||
if (!await productSyncer.sync())
|
||||
throw status(409, "Sync already in progress");
|
||||
})
|
||||
// Per-product sync
|
||||
.post("/:printfulProductId", async ({ params }) => {
|
||||
if (!await productSyncer.sync({ printfulProductIdsFilter: [params.printfulProductId] }))
|
||||
throw status(409, "Sync already in progress");
|
||||
}, { params: t.Object({ printfulProductId: t.Numeric() }) }),
|
||||
// Run sync
|
||||
.post("/:printfulProductId?", async ({ params: { printfulProductId } }) => {
|
||||
log.debug({ printfulProductId });
|
||||
const canSync = await productSyncer.sync({ filter: { printfulProductIds: printfulProductId } });
|
||||
if (!canSync) throw status(409, "Sync already in progress");
|
||||
}, { params: t.Object({ printfulProductId: t.Optional(t.Numeric()) }) }),
|
||||
)
|
||||
.get("/:printfulProductId", async ({ params }) => {
|
||||
const printfulProduct = await printful.Products.get(params.printfulProductId);
|
||||
@@ -200,7 +194,7 @@ export const app = new Elysia()
|
||||
case Printful.Webhook.Event.ProductUpdated: {
|
||||
const printfulProduct = payload.data.sync_product;
|
||||
log.info({ productId: printfulProduct.id }, "printful webhook: product updated");
|
||||
await productSyncer.sync({ printfulProductIdsFilter: [printfulProduct.id] });
|
||||
await productSyncer.sync({ filter: { printfulProductIds: printfulProduct.id } });
|
||||
break;
|
||||
}
|
||||
case Printful.Webhook.Event.ProductDeleted: {
|
||||
|
||||
Reference in New Issue
Block a user