Initial commit
This commit is contained in:
46
api/hooks/rating/get_read.js
Normal file
46
api/hooks/rating/get_read.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// @ts-check
|
||||
const { withAccount } = require("../lib/utils")
|
||||
;(function () {
|
||||
/** @type {HookResponse} */
|
||||
let hookResponse
|
||||
let request = context.request()
|
||||
if (context.user.auth()) return
|
||||
const orderId = Number(request.query("orderId"))
|
||||
if (orderId) {
|
||||
withAccount((login) => {
|
||||
let order = context.db.find("bigCommerceOrder", {
|
||||
filter: {
|
||||
bigCommerceId: orderId,
|
||||
customerBigCommerceId: login.bigCommerceId,
|
||||
},
|
||||
})[0]
|
||||
if (!order) {
|
||||
throw {
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Order not found",
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
hookResponse = {
|
||||
filter: {
|
||||
bigcommerceOrderId: orderId,
|
||||
},
|
||||
}
|
||||
|
||||
return hookResponse
|
||||
} else {
|
||||
hookResponse = {
|
||||
filter: context.filter,
|
||||
selector: {
|
||||
bigCommerceProductId: 1,
|
||||
rating: 1,
|
||||
comment: 1,
|
||||
title: 1,
|
||||
review_date: 1,
|
||||
},
|
||||
}
|
||||
return hookResponse
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user