Initial commit

This commit is contained in:
2025-10-02 08:54:03 +02:00
commit ea54638227
1642 changed files with 53677 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
const { getOrderById, getOrdersForCustomer, createInternalOrderObject } = require("../lib/bigcommerceRestAPI")
const { withAccount } = require("../lib/utils")
;(function () {
if (context.user.auth()) return {}
withAccount((login) => {
const orderId = context.request().param("id")
if (orderId) {
/** @type {Order} */
// @ts-ignore
const internalOrder = context.db.find("bigCommerceOrder", {
filter: { _id: orderId },
})[0]
if (internalOrder.customerTibiId !== login.tibiId) {
if (String(internalOrder?.customerBigCommerceId) !== String(login?.bigCommerceId)) {
throw {
message: "You don't have permission to access this order",
code: 403,
}
} else {
context.db.update("bigCommerceOrder", internalOrder.id, {
customerTibiId: login.tibiId,
})
}
}
const order = getOrderById(internalOrder.bigCommerceId)
order.tibiId = internalOrder.id
order.status = internalOrder.status
order.shipments = internalOrder.shipments
order.statusSetAt = internalOrder.statusSetAt
throw {
data: order,
status: 200,
}
} else {
const orders = getOrdersForCustomer(login.bigCommerceId)
orders.forEach((order) => {
let internalOrder = context.db.find("bigCommerceOrder", {
filter: { bigCommerceId: order.id },
})[0]
if (!internalOrder && order.id) {
const internalOrderReference = createInternalOrderObject(order.id)
internalOrder = context.db.create("bigCommerceOrder", internalOrderReference)
} else if (!internalOrder) return
order.tibiId = internalOrder?.id
order.status = internalOrder?.status
order.shipments = internalOrder?.shipments
order.statusSetAt = internalOrder?.statusSetAt
})
throw {
data: orders,
status: 200,
}
}
})
})()