general setup

This commit is contained in:
2024-03-11 17:14:31 +00:00
parent 5af89ab258
commit b82ab35bbe
342 changed files with 3672 additions and 10809 deletions

View File

@@ -0,0 +1,15 @@
;(function () {
const ratingId = context.request().param("id")
let rating = context.db.find("rating", {
filter: {
_id: ratingId,
},
})[0]
if (!rating.id)
throw {
status: 400,
error: "No id specified.",
}
// @ts-ignore
context["product"] = rating.productId
})()

View File

@@ -0,0 +1,17 @@
let { recalcRatingToProduct } = require("../lib/utils")
;(function () {
let product = context.db.find("bigCommerceProducts", {
filter: {
// @ts-ignore
_id: context["product"],
},
})[0]
if (!product)
throw {
status: 400,
error: "Could not resolve rating product",
}
//@ts-ignore
recalcRatingToProduct(product)
//TODO: delete rating from bigCommerce
})()

View File

@@ -0,0 +1,44 @@
// @ts-check
;(function () {
/** @type {HookResponse} */
let hookResponse
let request = context.request()
if (request.query("rateIt")) {
let orderNumber
orderNumber = Number(request.query("orderNumber"))
if (isNaN(orderNumber))
throw {
status: 400,
message: "Invalid order number.",
}
/*
TODO: reprogram to bigcommerce
let order = context.db.find("order", {
filter: {
sequence: orderNumber,
},
})[0]
if (!order)
throw {
status: 400,
message: "No entry with this order number.",
}
if (order.deliveryAddress.postcode != request.query("postalcode"))
throw {
status: 403,
message: "Error",
}
hookResponse = {
filter: {
orderId: order.id,
},
}*/
return hookResponse
}
})()

View File

@@ -0,0 +1,35 @@
/*
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" }
}
})()

View File

@@ -0,0 +1,6 @@
// @ts-check
let { sendOperatorRatingMail } = require("../lib/utils")
;(function () {
//TODO: has to be installed for this project,j ust copied
sendOperatorRatingMail()
})()

View File

@@ -0,0 +1,4 @@
let { validateAndModifyRating } = require("../lib/utils")
;(function () {
return { data: validateAndModifyRating(context.data) }
})()

View File

@@ -0,0 +1,25 @@
let { sendOperatorRatingMail, recalcRatingToProduct } = require("../lib/utils")
;(function () {
/** @type {ProductRating} */
let rating = context.data
/** @type {LocalProduct} */ // @ts-ignore
let product = context.db.find("bigCommerceProducts", {
filter: {
_id: rating.productId,
},
})[0]
if (!product)
throw {
status: 400,
error: "Product not found.",
}
recalcRatingToProduct(product)
/**@type {any} */
let oldRating = context["oldRating"]
if (!oldRating || JSON.stringify(rating.rating) != JSON.stringify(oldRating)) {
sendOperatorRatingMail()
}
})()

View File

@@ -0,0 +1,14 @@
;(function () {
if (!context?.user?.auth()?.id) {
console.log(context?.user?.auth()?.id)
//TODO: productInsideOrder(context.data) look in post
}
/** @type {ProductRating} */ // @ts-ignore
let ratingObj = context.db.find("rating", {
filter: {
_id: context.data.id,
},
})[0]
context["oldRating"] = ratingObj.rating
})()

View File

@@ -0,0 +1,4 @@
let { validateAndModifyRating } = require("../lib/utils")
;(function () {
return { data: validateAndModifyRating(context.data) }
})()