Initial commit
This commit is contained in:
17
api/hooks/rating/post_create.js
Normal file
17
api/hooks/rating/post_create.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const { productInsideOrder } = require("../lib/utils")
|
||||
|
||||
;(function () {
|
||||
if (!context?.user?.auth()?.id) {
|
||||
if (!context.data) throw { status: 400, error: "No data provided" }
|
||||
// @ts-ignore
|
||||
productInsideOrder(context.data)
|
||||
/** @type {ProductRating[]} */ // @ts-ignore
|
||||
let ratings = context.db.find("rating", {
|
||||
filter: {
|
||||
bigcommerceOrderId: context?.data?.bigcommerceOrderId,
|
||||
bigCommerceProductId: context?.data?.bigCommerceProductId,
|
||||
},
|
||||
})
|
||||
if (ratings.length) throw { status: 400, error: "Rating already existing" }
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user