Files
kontextwerk/api/hooks/wishlist/post_create.js
2025-10-02 08:54:03 +02:00

36 lines
1.1 KiB
JavaScript

const { removeWishlistEntry } = require("../lib/bigcommerceRestAPI.js")
const { withAccount } = require("../lib/utils")
const { createWishlistEntry } = require("../lib/bigcommerceRestAPI.js")
;(function () {
withAccount((login) => {
const productId = context.data.productId
const variantId = context.data.variantId
const customerId = login.bigCommerceId
if (context.data.delete) {
if (!productId || !variantId) {
throw {
message: "Invalid product or variant id",
code: 400,
}
}
const wishlist = removeWishlistEntry(customerId, productId, variantId)
throw {
status: 200,
data: wishlist,
}
}
if (!productId || !variantId) {
throw {
message: "Invalid product or variant id",
code: 400,
}
}
const wishlist = createWishlistEntry(productId, variantId, customerId)
throw {
status: 200,
data: wishlist,
}
})
})()