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,35 @@
const { withAccount } = require("../lib/utils")
;(function () {
const queryParam = context.request().query("orderId")
if (!queryParam) {
if (context.user.auth()) return
throw {
message: "orderId is required",
code: 400,
}
}
withAccount((login) => {
const order = context.db.find("bigCommerceOrder", {
filter: {
bigCommerceId: Number(queryParam),
},
})[0]
if (!order) {
throw {
message: "Order not found",
code: 404,
}
}
if (order.customerBigCommerceId !== login.bigCommerceId) {
throw {
message: "You don't have permission to access this order",
code: 403,
}
}
context.filter = {
bigCommerceId: order.bigCommerceId,
}
})
return context
})()

View File

@@ -0,0 +1,45 @@
const { withAccount } = require("../lib/utils")
const { getPrintfulOrder, cancelPrintfulOrder } = require("../lib/printfulRestAPI")
;(function () {
withAccount((login) => {
const order = context.db.find("bigCommerceOrder", {
filter: {
bigCommerceId: Number(context.data.bigCommerceId),
},
})[0]
if (!order)
throw {
message: "Order not found",
code: 404,
}
if (order.customerBigCommerceId !== login.bigCommerceId)
throw {
message: "You don't have permission to access this order",
code: 403,
}
const existingRevokeRequests = context.db.find("orderRevokeRequest", {
filter: {
bigCommerceId: context.data.bigCommerceId,
},
})
if (existingRevokeRequests.length > 0)
throw {
message: "Revoke request already exists",
code: 400,
}
if (!!order.status && order.status !== "draft") {
throw {
message: "Order is already in process",
code: 400,
}
}
const printfulOrder = getPrintfulOrder(order.bigCommerceId)
cancelPrintfulOrder(context.data.bigCommerceId)
context.data.status = "pending"
context.data.email = login.email
context.data.printfulId = printfulOrder.id
})
return context
})()

View File

@@ -0,0 +1,36 @@
const { serverBaseURL, logoPath, operatorEmail, noReplyEmail, contactEmail } = require("../config")
const { frontendBase } = require("../config-client")
const { getOrderById, updateOrderById } = require("../lib/bigcommerceRestAPI")
;(function () {
if (context.user.auth()) return
const bigCommerceOrder = getOrderById(context.data.bigCommerceId)
delete bigCommerceOrder.productObjs
delete bigCommerceOrder.shipping_addressObjs
bigCommerceOrder.status_id = 5
updateOrderById(bigCommerceOrder.id, { status_id: 5 })
const store = {
logo: `${serverBaseURL}${logoPath}`,
frontendBase,
}
const html = context.tpl.execute(context.fs.readFile("templates/orderRevokedApproval.html"), {
store,
})
context.smtp.sendMail({
to: contactEmail,
from: noReplyEmail,
fromName: "BinKrassDuFass",
replyTo: noReplyEmail,
subject: "New Order Revoke Request",
plain: `Die Bestellung von ${context.data.email} wurde abgebrochen.`,
})
context.smtp.sendMail({
to: context.data.email,
from: operatorEmail,
fromName: "BinKrassDuFass",
replyTo: noReplyEmail,
subject: "Abbruch deiner Bestellung",
html,
})
})()

View File

@@ -0,0 +1,43 @@
import { logoPath, noReplyEmail, operatorEmail, serverBaseURL } from "../config"
import { frontendBase } from "../config-client"
;(function () {
const oldOrderReturnRequest = context.db.find("orderReturnRequest", {
filter: {
_id: context.data.id,
},
})[0]
if (!oldOrderReturnRequest)
throw {
message: "Order return request not found",
code: 404,
}
if (oldOrderReturnRequest.status !== context.data.status) {
const oRR = context.data
const customer = context.db.find("bigCommerceCustomer", {
filter: { email: oRR.email },
})[0]
if (!customer) {
throw {
status: 404,
message: "Customer not found",
}
}
const store = {
logo: `${serverBaseURL}${logoPath}`,
frontendBase,
}
const html = context.tpl.execute(context.fs.readFile("templates/statusUpdateReturnRequest.html"), {
store,
})
context.smtp.sendMail({
to: oRR.email,
from: operatorEmail,
fromName: "BinKrassDuFass",
replyTo: noReplyEmail,
subject: "Stornierung Ihrer Bestellung",
html,
})
}
})()