Initial commit
This commit is contained in:
35
api/hooks/orderRevokeRequest/get_read.js
Normal file
35
api/hooks/orderRevokeRequest/get_read.js
Normal 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
|
||||
})()
|
||||
45
api/hooks/orderRevokeRequest/post_create.js
Normal file
45
api/hooks/orderRevokeRequest/post_create.js
Normal 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
|
||||
})()
|
||||
36
api/hooks/orderRevokeRequest/post_return.js
Normal file
36
api/hooks/orderRevokeRequest/post_return.js
Normal 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,
|
||||
})
|
||||
})()
|
||||
43
api/hooks/orderRevokeRequest/put_update.js
Normal file
43
api/hooks/orderRevokeRequest/put_update.js
Normal 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,
|
||||
})
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user