/* TODO: reprogram to bigcommerce function productInsideOrder(orderRating) { let order = context.db.find("order", { filter: { _id: orderRating.orderId }, })[0] if (!order) throw { error: "No Order object with given ID.", status: 400 } let productsInOrder = order.cart.map((entry) => entry.product.id) if (productsInOrder.length == 0) throw { error: "No products inside the Order.", status: 400 } let productInRating = orderRating.productId let productInsideOrder = productsInOrder.includes(productInRating) if (!productInsideOrder) throw { error: "Rated products are not inside the Order.", status: 400 } } */ ;(function () { if (!context?.user?.auth()?.id) { console.log(context?.user?.auth()?.id, "=IDD") //productInsideOrder(context.data) /** @type {ProductRating[]} */ // @ts-ignore let ratings = context.db.find("rating", { filter: { bigCommerceOrderId: context?.data?.orderId, productId: context?.data?.productId, }, }) if (ratings.length) throw { status: 400, error: "Rating already existing" } } })()