Implement product updating logic
This commit is contained in:
@@ -15,18 +15,21 @@ const server = Bun.serve({
|
||||
async POST(req) {
|
||||
const payload: Printful.Webhook.EventPayload = await req.json()
|
||||
console.log(JSON.stringify(payload));
|
||||
console.log("PRINTFUL WEBHOOK: " + payload.type);
|
||||
switch (payload.type) {
|
||||
// ADD/UPDATE
|
||||
case Printful.Webhook.Event.ProductUpdated:
|
||||
const printfulProduct = await Printful.getSyncProduct(payload.data.sync_product.id)
|
||||
const productRecord = productRecords.findFromPrintful(payload.data.sync_product.id)
|
||||
|
||||
if (productRecord) {
|
||||
await Webflow.createProduct(printfulProduct, productRecords);
|
||||
await Webflow.updateProduct(printfulProduct, productRecords);
|
||||
}
|
||||
else {
|
||||
|
||||
await Webflow.createProduct(printfulProduct, productRecords);
|
||||
}
|
||||
break;
|
||||
// DELETE
|
||||
case Printful.Webhook.Event.ProductDeleted:
|
||||
break;
|
||||
}
|
||||
@@ -38,4 +41,6 @@ const server = Bun.serve({
|
||||
development: true
|
||||
})
|
||||
|
||||
productRecords.add({ webflowProductId: 123, printfulProductId: 321 });
|
||||
|
||||
console.log(`Listening on ${server.url}`);
|
||||
|
||||
Reference in New Issue
Block a user